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.

zero_phase_dtft(x,M)
function [x X] = zero_phase_dtft(x,M)
% This function is an implementation of the "zero phase DTFT" of a given
% symmetric (even) sequence x[n].
% It is also assumed that x[n] is given in original symmetric around zero form.
% M is the selected size of the final DFT that is going to simulate the DTFT.
% Make sure x is row vector for subsequent processing:
x = x(:).';
N = length(x);

if mod(N,2)==0  % i.e. if length is even and not odd as required.
    disp('Given sequence x[n] sould be symmetric and of odd length');
    return;
end

% Add some zeros to create a much longer sequence of size M.
x = [x zeros(1,M-N)];

% Circularly shift half of the sequence to make it symmetric around
% the middle sample (N-1)/2.
x = [x((N+1)/2:end) x(1:(N-1)/2)];

% Now compute the DFT of x[n]: 
X = fft(x);

X = X(1:M/2);  % Keep only the samples that correspond to frequencies [0 pi].

Contact us