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.
|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.
% 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.
% 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 = [r x(k) zeros(1,N-1)]; % Insert N-1 zeros between the samples of x[n].
% 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);
y(k) = s(k*N);