function [y,ys,b]=deltamod(x,t,fs,delta) % % function [y,ys,b]=deltamod(x,t,fs,delta) % % This function will produce: the output bit pattern for the delta % modulation of x, at sample rate fs (i.e., fs bits/sec), using a step % size of "delta". y is the delta mod approximation, ys is the smoothed % signal after a simple LPF at the receiver, and b is the output bit % pattern. t is the input time vector associated with input x and outputs y and ys. y=[ ]; delt=t(2)-t(1); % time between samples in x delf=1/delt; % frequency of original samples num=round(delf/fs); % this is the number of samples of x that will be % associated w/every bit in output if (num < 2) num disp(sprintf('Sample frequency looks to be too low, exiting ....')); return; end b=zeros(1,round(length(x)/num)); y=zeros(size(x)); bindex=1; currentvalue=0; y(1:num)=0; % set up first step... if (y(1) <= x(1)) y(1:num)=delta; currentvalue=delta; else y(1:num)=-delta; currentvalue=-delta; end currentindex=num+1; for i=num+1:num:length(x) if (x(i) > currentvalue) y(currentindex:currentindex+num)=currentvalue+delta; b(bindex)=1; else y(currentindex:currentindex+num)=currentvalue-delta; b(bindex)=0; end currentvalue=y(currentindex); currentindex=currentindex+num; bindex=bindex+1; end y=y(1:length(x)); N=round(num*2); ys=filter(1/N*ones(1,N),1,y);