fractional delay filters using farrow structures -凯发k8网页登录
this example shows how to design digital fractional delay filters that are implemented using farrow structures. digital fractional delay filters are useful tools to fine-tune the sampling instants of signals. they are for example typically found in the synchronization of digital modems where the delay parameter varies over time. this example illustrates the farrow structure, a popular method for implementing time-varying fir fractional delay filters.
ideal fractional delay filter
the ideal fractional delay filter is a linear phase allpass filter. its impulse response is a time-shifted discrete sinc function that corresponds to a non causal filter. since the impulse response is infinite, it cannot be made causal by a finite shift in time. it is therefore non realizable and must be approximated.
the farrow structure
to compute the output of a fractional delay filter, we need to estimate the values of the input signal between the existing discrete-time samples. special interpolation filters can be used to compute new sample values at arbitrary points. among those, polynomial-based filters are of particular interest because a special structure - the farrow structure - permits simple handling of coefficients. in particular, the tunability of the farrow structure makes its well-suited for practical hardware implementations.
maximally-flat fir approximation (lagrange interpolation)
lagrange interpolation is a time-domain approach that leads to a special case of polynomial-based filters. the output signal is approximated with a polynomial of degree m. the simplest case (m=1) corresponds to linear interpolation. let's design and analyze a linear fractional delay filter that will split the unit delay by various fractions:
nx = 1024; nf = 5; yw = zeros(nx,nf); transferfuncestimator = dsp.transferfunctionestimator( ... 'spectralaverages',25,'frequencyrange','onesided'); arrplotphasedelay = dsp.arrayplot('plottype','line','ylimits',[0 1.5], ... 'ylabel','phase delay','sampleincrement',1/512); arrplotmag = dsp.arrayplot('plottype','line','ylimits',[-10 1], ... 'ylabel','magnitude (db)','sampleincrement',1/512); fracdelay = dsp.variablefractionaldelay; xw = randn(nx,nf); transferfuncestimator(xw,yw); w = getfrequencyvector(transferfuncestimator,2*pi); w = repmat(w,1,nf); tic, while toc < 2 yw = fracdelay(xw,[0 0.2 0.4 0.6 0.8]); h = transferfuncestimator(xw,yw); arrplotmag(20*log10(abs(h))) arrplotphasedelay(-angle(h)./w) end release(fracdelay) release(transferfuncestimator) release(arrplotmag)
release(arrplotphasedelay)
for any value of the delay, the ideal filter should have both a flat magnitude response and a flat phase delay response. the approximation is correct only for the lowest frequencies. this means that in practice the signals need to be over-sampled for the linear fractional delay to work correctly. here you apply two different fractional delays to a sine wave and use the time scope to overlay the original sine wave and the two delayed versions. a delay of 0.2 samples with a sample rate of 1000 hz, corresponds to a delay of 0.2 ms.
scope = timescope('samplerate',1000, ... 'ylimits',[-1 1], ... 'timespan',.02, ... 'timespanoverrunaction','scroll'); sine = dsp.sinewave('frequency',50,'samplesperframe',nx); tic, while toc < 2 x = sine(); y = fracdelay(x,[.2 .8]); % delay by 0.2 ms and 0.8 ms scope([x,y(:,1),y(:,2)]) end release(fracdelay) release(scope);
higher order lagrange interpolators can be designed. let's compare a cubic lagrange interpolator with a linear one:
farrowfracdelay = dsp.variablefractionaldelay( ... 'interpolationmethod','farrow','maximumdelay',1025); nf = 2; yw = zeros(nx,nf); xw = randn(nx,nf); h = transferfuncestimator(xw,yw); w = getfrequencyvector(transferfuncestimator,2*pi); w = repmat(w,1,nf); tic, while toc < 2 % run for 2 seconds yw(:,1) = fracdelay(xw(:,1),0.4); % delay by 0.4 ms yw(:,2) = farrowfracdelay(xw(:,2),1.4); % delay by 1.4 ms h = transferfuncestimator(xw,yw); arrplotmag(20*log10(abs(h))) arrplotphasedelay(-unwrap(angle(h))./w) end release(fracdelay) release(transferfuncestimator) release(arrplotmag)
release(arrplotphasedelay)
increasing the order of the polynomials slightly increases the useful bandwidth when lagrange approximation is used. the length of the differentiating filters, that is, the number of pieces of the impulse response (number of rows of the 'coefficients' property) is equal to the length of the polynomials (number of columns of the 'coefficients' property). other design methods can be used to overcome this limitation. also notice how the phase delay of the third order filter is shifted from 0.4 to 1.4 samples at dc. since the cubic lagrange interpolator is a 3rd order filter, the minimum delay it can achieve is 1. for this reason, the delay requested is 1.4 ms instead of 0.4 ms for this case.
sine = dsp.sinewave('frequency',50,'samplesperframe',nx); tic, while toc < 2 x = sine(); y1 = fracdelay(x,0.4); y2 = farrowfracdelay(x,1.4); scope([x,y1,y2]) end release(fracdelay) release(scope);
time-varying fractional delay
the advantage of the farrow structure over a direct-form fir resides in its tunability. in many practical applications, the delay is time-varying. for each new delay we would need a new set of coefficients in the direct-form implementation but with a farrow implementation, the polynomial coefficients remain constant.
tic, while toc < 5 x = sine(); if toc < 1 delay = 1; elseif toc < 2 delay = 1.2; elseif toc < 3 delay = 1.4; elseif toc < 4 delay = 1.6; else delay = 1.8; end y = farrowfracdelay(x,delay); scope([x,y]) end release(fracdelay) release(scope);