MatLab Solutions: "Introduction to Digital Signal Processing: A Computer Laboratory Textbook".
29 Oct 2012
25 Nov 2013)
These files are the MatLab solutions of exercises contained in the above DSP lab textbook.
function z = fastconvreal(x,y)
% Compute the linear convolution of 2 real sequences via FFT's.
% This function takes care of the sizes of the 2 input sequences and zero-pads them
% to a common length L = 2^n.
% Input arguments:
% x is a row vector that contains the real-valued sequence x[n].
% y is a row vector that contains the real-valued sequence y[n].
% Output Arguments:
% z : vector containing the real convolution values of x[n] and y[n].
% Make sure x and y are row vectors.
x = x(:).';
y = y(:).';
N = length(x);
M = length(y);
L = 2^nextpow2(N+M-1);
x1 = [x zeros(1,L-N)]; % Zero-pad as required to make the length
y1 = [y zeros(1,L-M)]; % of both sequences equal to L=2^n for max fft() performance.
% Calculate the real version of the fft for speed benefits:
X = fftreal(x1);
Y = fftreal(y1);
Z = X.*Y;
% Calculate the real version of the ifft for speed benefits:
z1 = ifftreal(Z);
% Return the values and time indices of the linear convolution:
z = z1(1,1:N+M-1);