% To generate DM signals with different step sizes, we apply
the
% same signal g(t) as used in the PCM example.
% The MATLAB program ExDM.m applies three step sizes:
% △1=0.2, △2=2△1, and △3=4△1.
% ( file name: ExDM.m )
% Example of sampling, quantization, and zero-order hold
clear; clf;
td=0.002; % original sampling
rate 500 Hz
t=[0:td:1.]; % time interval of 1 second
xsig=sin(2*pi*t)-sin(6*pi*t); %
1Hz+3Hz sinusoids
Lsig=length(xsig);
ts=0.02;
Nfact=ts/td;
% send the signal through a
16-level uniform quantizer
Delta=0.2; % First select a small Delta=0.2 in
DM
s_DMout1=deltamod(xsig,Delta,td,ts);
% obtained the DM signal
% plot the original signal and
the DM signal in time domain
figure(1);
subplot(311); sfig1=plot(t,xsig,'r',t,s_DMout1(1:Lsig),'b');
set(sfig1,'Linewidth',2);
title(' Signal {\it g}({\it t}) and DM signal ')
xlabel('time (sec.)'); axis([0 1 -2.2 2.2]);
ylabel('△1=0.2');
%
% Apply DM again by doubling
the Delta
Delta2=2*Delta;
s_DMout2=deltamod(xsig,Delta2,td,ts);
% obtained the DM signal
% plot the original signal and
the DM signal in time domain
subplot(312); sfig2=plot(t,xsig,'r',t,s_DMout2(1:Lsig),'b');
set(sfig2,'Linewidth',2);
title(' Signal {\it g}({\it t}) and DM signal with doubled
stepsize')
xlabel('time (sec.)'); axis([0 1 -2.2 2.2]);
ylabel('△2=2△1');
%
Delta3=2*Delta2; % Double the DM Delta again
s_DMout3=deltamod(xsig,Delta3,td,ts);
% obtained the DM signal
% plot the original signal and
the DM signal in time domain
subplot(313); sfig3=plot(t,xsig,'r',t,s_DMout3(1:Lsig),'b');
set(sfig3,'Linewidth',2);
title(' Signal {\it g}({\it t}) and DM signal with quadrupled
stepsize')
xlabel('time (sec.)'); axis([0 1 -2.2 2.2]); ylabel('△3=4△1');
%
-------------------------------------------------------------
% 程序调用函数
%
-------------------------------------------------------------
% Delta Modulation
% We illustrate the practical effect of stepsize selection △
% in the design of DM encoder. The basic function to
% implement DM is given deltamod.m.
% ( file name: deltamod.m )
function s_DMout= deltamod(sig_in,Delta,td,ts)
% Usage
% s_DMout = deltamod(xsig,Delta,td,ts)
% Delta - DM stepsize
% sig_in - input signal
vector
% td - original signal sampling
period of sig_in
% ts - new sampling
period
% NOTE: td*fs must be a positive integer;
% Function outputs:
% s_DNout - DM sampled output
if (rem(ts/td,1)==0)
nfac=round(ts/td);
p_zoh=ones(1,nfac);
s_down=downsample(sig_in,nfac);
Num_it=length(s_down);
s_DMout(1)=-Delta/2;
for
k=2:Num_it
xvar=s_DMout(k-1);
s_DMout(k)=xvar+Delta*sign(s_down(k-1)-xvar);
end
s_DMout=kron(s_DMout,p_zoh);
else
warning('error! ts/td is not an integer!');
s_DMout=[];
end
end
%
-------------------------------------------------------------------------------------
% 参考文献
% B.P.拉兹,丁峙. 现代数字与模拟通信系统[M]. 第4版. 北京:电子工业出版社,2011:368-371