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.

bench_dtft.m
```% This routine compares the time needed to execute various DTFT implementations.
% Namely, the custom functions: my_DTFT, my_DTFT2, my_DTFT3 and my_DTFT4.
clc; clear; close all;

% Various sizes of input signals:
N = 2.^(3:12);
L = length(N);

time_DTFT1 = zeros(1,L);
time_DTFT2 = zeros(1,L);
time_DTFT3 = zeros(1,L);
time_DTFT4 = zeros(1,L);

for k=1:L

x = randn(1,N(k)) + 1i*randn(1,N(k));
n = 0:N(k)-1;

tic
[w X1] = my_DTFT(x,n);
time_DTFT1(k) = toc;

tic
[w X2] = my_DTFT2(x,n,[-pi pi]);
time_DTFT2(k) = toc;

tic
[w X3] = my_DTFT3(x,n);
time_DTFT3(k) = toc;

tic
[w X4] = my_DTFT4(x,n);
time_DTFT4(k) = toc;

end

%% Now plot the results.
figure('Name','Benchmarking of DTFT execution');
semilogy(log2(N),time_DTFT1,'*-');
hold on;
semilogy(log2(N),time_DTFT2,'c*-');
semilogy(log2(N),time_DTFT3,'g*-');
semilogy(log2(N),time_DTFT4,'m*-');
grid;
axis tight;
legend('DTFT1','DTFT2','DTFT3','DTFT4','Location','NorthWest');
title('Execution Time for Various DTFT Implementations');
xlabel('log_2(length(x))');
ylabel('Execution Time (sec)');

%% Compare the results:
figure(2);
subplot(2,1,1);
plot(w,real(X1) - real(X3));
title('\Ree\{X_1[k]\} - \Ree\{X_3[k]\}');
grid on;
axis tight;

subplot(2,1,2);
plot(w,imag(X1) - imag(X3),'r');
title('\Imm\{X_1[k]\} - \Imm\{X_3[k]\}');
grid on;
axis tight;

figure(3);
subplot(2,1,1);
plot(w,real(X1) - real(X4));
title('\Ree\{X_1[k]\} - \Ree\{X_4[k]\}');
grid on;
axis tight;

subplot(2,1,2);
plot(w,imag(X1) - imag(X4),'r');
title('\Imm\{X_1[k]\} - \Imm\{X_4[k]\}');
grid on;
axis tight;
```