Example 4.1.8 from Orfanidis
(a)
a = 0.75; M = 14; b = 1-a; h = b*(a).^(0:14); ydc = sum(h); %Generate square wave, L = 200, period K = 50 samples L=200; K = 50; n=0:L-1; x = [mod(n,K)<K/2]; %convolve the square wave with h(n) y = conv(h,x); plot(n,y(1:length(n))) hold on plot(n,x,'--') axis([0 200 -0.5 2.5]) xlabel('time samples') legend('-','output','--','input')(b)
h = [0.2 -1 2 -2 1 -0.2]; ydc = sum(h); %Generate square wave, L = 200, period K = 50 samples L=200; K = 50; n=0:L-1; x = [mod(n,K)<K/2]; %convolve the square wave with h(n) y = conv(h,x); plot(n,y(1:length(n))) hold on plot(n,x,'--') axis([0 200 -1.5 2.5]) xlabel('time samples') legend('-','output','--','input')