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.

test_idct.m
% Test fot my_DCT.m and my_IDCT.m scripts.

clc; clear; close all;

%% Test signal definitions.
N = 256;
x = randn(1,N) + 1i*randn(1,N);  % Complex-valued input signal.
y = randn(1,N);                             % Real-valued input signal.

% Calculate the DCT and IDCT of the complex-valued case:
X1 = dct(x);
X2 = my_DCT(x);

x1 = idct(X1);
x2 = my_IDCT(X2);

% Calculate the DCT and IDCT of the real-valued case:
Y1 = dct(y);
Y2 = my_DCT(y);

y1 = idct(Y1);
y2 = my_IDCT(Y2);

%% Plot the Results for the complex-valued case:
figure(1);
subplot(2,2,1);
stem(real(X1));
hold on;
stem(real(X2),'r.');
grid on;
axis tight;
title('\Ree\{X_1[k]\} (blue) vs \Ree\{X_2[k]\} (red) ');

subplot(2,2,2);
stem(imag(X1));
hold on;
stem(imag(X2),'r.');
grid on;
axis tight;
title('\Imm\{X_1[k]\} (blue) vs \Imm\{X_2[k]\} (red) ');

subplot(2,2,3);
stem(real(x));
hold on;
stem(real(x2),'r.');
grid on;
axis tight;
title('\Ree\{x[n]\} (blue) vs \Ree\{x_2[n]\} (red) ');

subplot(2,2,4);
stem(imag(x));
hold on;
stem(imag(x2),'r.');
grid on;
axis tight;
title('\Imm\{x[n]\} (blue) vs \Imm\{x_2[n]\} (red) ');

%% Plot the Results for the real-valued case:
figure(2);
subplot(2,1,1);
stem(Y1);
hold on;
stem(Y2,'r.');
grid on;
axis tight;
title('Y_1[k] (blue) vs Y_2[k] (red) ');

subplot(2,1,2);
stem(y);
hold on;
stem(y2,'r.');
grid on;
axis tight;
title('y[n] (blue) vs y_2[n] (red) ');