DSPRelated.com
Forums

How can I calculate group delay of a FIR filter on PC?

Started by Unknown May 18, 2005
I am trying to calculate group delay of a FIR filter on PC. I use
Matlab but I am confused with its algorithm. Basically the Matlab
algorithm says this,

group_delay(f) = Fourier transform of {n * h[n]} where h[n] is impulse
response of the filter.

But the Fourier transform of h[n]*n is the differentiation of H(w) with
respect to w and not differentiation of phase of H(w) with respect to
w, i.e.

h[n]*n <------> j * d(H(w))/dw

Am I missing something?

What would people normally do to calculate group delay of a FIR filter
on a PC?

Thanks.

cykhung@hotmail.com wrote:
> I am trying to calculate group delay of a FIR filter on PC. I use > Matlab but I am confused with its algorithm. Basically the Matlab > algorithm says this, > > group_delay(f) = Fourier transform of {n * h[n]} where h[n] is impulse > response of the filter. > > But the Fourier transform of h[n]*n is the differentiation of H(w) with > respect to w and not differentiation of phase of H(w) with respect to > w, i.e. > > h[n]*n <------> j * d(H(w))/dw > > Am I missing something? > > What would people normally do to calculate group delay of a FIR filter > on a PC? > > Thanks.
Does the FIR have symmetric coefficients? That is, is its phase linearly proportional to frequency? If so, its group delay is independent of frequency and equal to half the time needed for a sample to traverse it. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
<cykhung@hotmail.com> wrote in message 
news:1116440987.008061.283230@f14g2000cwb.googlegroups.com...
> group_delay(f) = Fourier transform of {n * h[n]} where h[n] is impulse > response of the filter.
Not quite (see below)
> But the Fourier transform of h[n]*n is the differentiation of H(w) with > respect to w and not differentiation of phase of H(w) with respect to > w, i.e. > > h[n]*n <------> j * d(H(w))/dw
Since this is a discrete time Fourier transform, it's actually j*dH(e^jwT)/dw
> Am I missing something?
You need to get the DTFT of h[n] as well. Then you can calculate the group delay: D(w) = Real_Part( ( j*dH(e^jwT)/dw ) / H(e^jwT) ) -- Matt
I guess my ultimate question is:

Is it possible to find the group delay of a FIR filter with arbitrary
coefficients (i.e. not necessarily symmetric or antisymmetric) on a PC
without doing an actual numerical differentiation in frequency domain?

Thanks.

<cykhung@hotmail.com> wrote in message 
news:1116488523.983794.231800@z14g2000cwz.googlegroups.com...
>I guess my ultimate question is: > > Is it possible to find the group delay of a FIR filter with arbitrary > coefficients (i.e. not necessarily symmetric or antisymmetric) on a PC > without doing an actual numerical differentiation in frequency domain?
The answer probably depends on your objective in asking the question. Are you against using phase at all and want to make a direct delay measurement? You could apply a sinusoidal step and determine the delay at that frequency in the steady state. That doesn't seem easier to me but then I don't know if you're looking for easier or just "different". And, that's just a clunky way of doing a frequency domain measurement I think.... You could determine phase using a root locus plot. But you'd still have to figure out delay. Maybe Jerry will comment. If there's a trick - I don't know what it is. Fred
"Fred Marshall" <fmarshallx@remove_the_x.acm.org> wrote in message 
news:S4ydna17yuOjLxHfRVn-rQ@centurytel.net...
> > <cykhung@hotmail.com> wrote in message > news:1116488523.983794.231800@z14g2000cwz.googlegroups.com... >>I guess my ultimate question is: >> >> Is it possible to find the group delay of a FIR filter with arbitrary >> coefficients (i.e. not necessarily symmetric or antisymmetric) on a PC >> without doing an actual numerical differentiation in frequency domain? > > The answer probably depends on your objective in asking the question. Are > you against using phase at all and want to make a direct delay > measurement? > > You could apply a sinusoidal step and determine the delay at that > frequency in the steady state. That doesn't seem easier to me but then I > don't know if you're looking for easier or just "different". And, that's > just a clunky way of doing a frequency domain measurement I think.... > > You could determine phase using a root locus plot. But you'd still have > to figure out delay. Maybe Jerry will comment. > > If there's a trick - I don't know what it is. > > Fred
It appears that Matt already gave you the answer.... Fred
<cykhung@hotmail.com> wrote in message 
news:1116488523.983794.231800@z14g2000cwz.googlegroups.com...
>I guess my ultimate question is: > > Is it possible to find the group delay of a FIR filter with arbitrary > coefficients (i.e. not necessarily symmetric or antisymmetric) on a PC > without doing an actual numerical differentiation in frequency domain? > > Thanks.
Yes. I just answered that question. -- Matt
Hi Matt,

Thanks for the answer. I think there is ramping term missing in the
equation. I found the site which describes the method used in Matlab. I
think he is the author of the method being used in Matlab.

http://ccrma.stanford.edu/~jos/filters/Numerical_Computation_Group_Delay.html

It is an elegant solution. Now I know why we need to study complex
variable analysis at undergrad.

cykhung@hotmail.com wrote:
> Hi Matt, > > Thanks for the answer. I think there is ramping term missing in the > equation. I found the site which describes the method used in Matlab. I > think he is the author of the method being used in Matlab. > > http://ccrma.stanford.edu/~jos/filters/Numerical_Computation_Group_Delay.html > > It is an elegant solution. Now I know why we need to study complex > variable analysis at undergrad.
Now you know _one_ of the reasons. There are others. Jerry -- Been there. Done that. Forgot already. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;

cykhung@hotmail.com wrote:

> What would people normally do to calculate group delay of a FIR filter > on a PC?
What Monson Hays says to do in his Schaum's Outline on DSP is: function d=grpdlyfft(t) % Usage: d=grpdlyfft(t) % t=time domain functions (FIRs) % d=group delay of frequency domain functions in % samples f=fft(t); g=fft(t.*repmat([0:size(t,1)-1]',1,size(t,2))); d=(real(f).*real(g)+imag(f).*imag(g))./(abs(f).^2); He derives it in the Schaum's outline in the solved problems but I don't remember the derivation details offhand and have packed away my copy. My implementation is a bit complicated on the second executable line by the fact that it operates on a column matrix of time sequences (FIRs) to produce a separate result for each column the same way that fft() does. If only one FIR is given, the second executable line becomes: g=fft(t.*[0:length(t)-1]); which may make the logic clearer. By the "Derivative Property" of the DFT, g is the derivative of fft(t) with respect to frequency divided by i. Bob -- "Things should be described as simply as possible, but no simpler." A. Einstein