Code covered by the BSD License

MatLab Solutions: "Introduction to Digital Signal Processing: A Computer Laboratory Textbook".

Ilias Konsoulas (view profile)

29 Oct 2012 (Updated )

These files are the MatLab solutions of exercises contained in the above DSP lab textbook.

ex332.m
% Exercise 3.3.2. A Cascaded System.

clc; clear; close all;

%% Step (a). Display the Magnitude of H1(j) and H2(j).
h1 = [ -0.04 0.04 0.3 -0.6 0.3 0.04 -0.04 ];
n1 = 0:6;

h2 = [  0.09 -0.12 -0.5 -0.5 0.12 0.09];
n2 = 0:5;

[w H1] = my_DTFT(h1,n1);

[w H2] = my_DTFT(h2,n2);

subplot(3,2,1);
plot(w,abs(H1));
set(gca,'XTick',[0 pi/4 pi/2 3*pi/4 pi]);
set(gca,'XTickLabel',{'0','pi/4','pi/2','3pi/4','pi' })
ylim([0 1.15]);
xlim([0 pi]);
grid on;
title('|{\itH_1}(j\omega)|');

subplot(3,2,2);
plot(w,angle(H1));
set(gca,'XTick',[0 pi/4 pi/2 3*pi/4 pi]);
set(gca,'XTickLabel',{'0','pi/4','pi/2','3pi/4','pi' })
xlim([0 pi]);
grid on;
title('\angle{\itH_1}(j\omega)');

subplot(3,2,3)
plot(w,abs(H2));
set(gca,'XTick',[0 pi/4 pi/2 3*pi/4 pi]);
set(gca,'XTickLabel',{'0','pi/4','pi/2','3pi/4','pi' })
ylim([0 1.15]);
xlim([0 pi]);
grid on;
title('|{\itH_2}(j\omega)|');

subplot(3,2,4)
plot(w,angle(H2));
set(gca,'XTick',[0 pi/4 pi/2 3*pi/4 pi]);
set(gca,'XTickLabel',{'0','pi/4','pi/2','3pi/4','pi' })
xlim([0 pi]);
grid on;
title('\angle{\itH_2}(j\omega)');
%% Step (b). Display the Magnitude of H3(j) = DTFT{conv(h1[n],h2[n])}.

[n3 h3] = my_conv(h1,h2,n1,n2); % This signal has length of 7+6-1 = 12.
% Durates from n = 0 to n = 11.
[w H3] = my_DTFT(h3,n3);

%% Plot the results.
subplot(3,2,6)
plot(w,angle(H3));
set(gca,'XTick',[0 pi/4 pi/2 3*pi/4 pi]);
set(gca,'XTickLabel',{'0','pi/4','pi/2','3pi/4','pi' })
hold on;
xlim([0 pi]);
grid on;
title('\angle{\itH_3}(j\omega) = \angle[{\itH_1}(j\omega)*{\itH_2}(j\omega)]');

subplot(3,2,5)
plot(w,abs(H3));
set(gca,'XTick',[0 pi/4 pi/2 3*pi/4 pi]);
set(gca,'XTickLabel',{'0','pi/4','pi/2','3pi/4','pi' })
xlim([0 pi]);
grid on;
title('{|\itH_3}(j\omega)| = |{\itH_1}(j\omega)|*|{\itH_2}(j\omega)|');
hold on;

% Verify that this is true:
disp('Press any key to continue...');
pause();
stem(w,abs(H1.*H2),'r.','Marker','none');

subplot(3,2,6)
stem(w,angle(H1.*H2),'r.','Marker','none');
xlim([0 pi]);
grid on;