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.

fraction_delay(x, h, N)
function y = fraction_delay(x, h, N)
% This function induces a fractional sample delay by 1/N to the input signal x.
% Inputs:
% x: vector containing the signal that is going to undergo a fractional delay.
% h: vector conataining a low-pass filter necessary for this operation.
% N: the fractional delay factor.
% Outputs:
% y: vector containing the signal x[n] delayed by a factor of 1/N sample.
% Caution: Works for low-pass filters h of odd length.
Lx = length(x);
Lh = length(h);

% First Upsample x[n] by a factor of  N.
r =[];
for k=1:Lx;
      r = [r x(k) zeros(1,N-1)];  % Insert N-1 zeros between the samples of x[n].
end

% Delay the whole upsampled sequence by one sample by inserting a zero at the first place.
r = [0  r];

s = conv(h,r); % Filter the delayed r[n] sequence using the given low-pass filter h.

% Finally, downsample by a factor of N:
Ly = floor(length(s)/N);
y = zeros(1,Ly);
for k=1:Ly         
    y(k) = s(k*N);
end

Contact us