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.

fastconv3(x,y,nx,ny)
```function [nz  z] = fastconv3(x,y,nx,ny)
% Compute a linear convolution via DFT's.
% The only disadvantage of this method is that we have to know the exact
% size of both signals beforehand. Therefore, this method cannot be applied
% for on-line convolution computation.
% 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 valued sequence x[n].
%   y is a row vector that contains the valued sequence y[n].
%   nx : the time indices of input sequence x[n].
%   ny : the time indices of input sequence y[n].
% As you can see, it also returns the time indices of the computed convolution sequence.
% Output Arguments:
%   z : vector containing the convolution values of x[n] and y[n].
%   nz : vector containing the time indices of convolution output sequence z[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.

X = fft(x1);
Y = fft(y1);

Z = X.*Y;

z1 = ifft(Z);

% Return the values and time indices of the linear convolution:
z = z1(1,1:N+M-1);
nz = nx(1)+ny(1):nx(end)+ny(end);```