PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

84 Practical MATLAB® Applications for Engineers


ylabel(‘Amplitude’);xlabel(‘time index n’)
title(‘f(n) is decimated with M=10’)

figure(2); % up-sample with L = 2, 4, 10
subplot(2,2,1)
stem(n,f); hold on; plot(n,f,n,yzero(1:100))
title(‘f(n) vs n’);ylabel(‘Amplitude’);
xlabel(‘time index n’);
subplot(2,2,2)
gL2 = interp(f,2);
nL2 = 0:100*2-1;
stem(nL2,gL2(1:200));hold on; plot(nL2,yzero(1:200));
title(‘f(n) is upsampled with L=2’); ylabel(‘Amplitude’);
xlabel(‘time index n’);
subplot(2,2,3)
gL4 = interp(f,4);
nL4 = 0:100*4-1;
stem(nL4,gL4(1:400)); hold on;
plot (nL4,yzero(1:400));
ylabel(‘Amplitude’);xlabel(‘time index n’);
title(‘f(n) is upsampled with L=4’)
subplot(2,2,4)
gL10= interp(f,10);
nL10 = 0:100*10-1;
stem(nL10,gL10(1:1000));hold on;
ylabel(‘Amplitude’); xlabel(‘time index n’)
title(‘f(n) is upsampled with L=10’)

figure(3)
% re-sample by ratio of L=3/M=2 & L=2/M=3
subplot(3,1,1)
stem(n,f);hold on; plot(n,f,n,yzero(1:100))
title(‘f(n) vs n’);
ylabel(‘Amplitude’); xlabel(‘time index n’);
subplot(3,1,2)
gr32= resample(f,3,2);
nr32 = 0:100*3/2-1;yzeros = zeros(1,length(nr32));
stem(nr32,gr32(1:100*3/2));hold on;plot(nr32,yzeros);
ylabel(‘Amplitude’); xlabel(‘time index n’);
subplot(3,1,3)
gr23 = resample(f,2,3);
nr23 = 0:100*2/3-1;
yzero = zeros(1,length(nr23));
stem(nr23,gr23(1:100*2/3));
hold on;plot(nr23,yzero);
axis([0 65 -5 5]);
ylabel(‘Amplitude’); xlabel(‘time index n’)

Back in the command window, the script fi le up_down_samples is executed and the
results are shown in Figures 1.70 through 1.72.
Free download pdf