Code covered by the BSD License  

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

image thumbnail

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

by

 

29 Oct 2012 (Updated )

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

fastconvreal2(x,y,nx,ny)
function [nz z] = fastconvreal2(x,y,nx,ny)
% 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].
%   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.

% Use the real-valued versions of the fft and ifft to perform the needed operations:
X = fftreal(x1);
Y = fftreal(y1);

Z = X.*Y;

z1 = ifftreal(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);

Contact us