Hey there,
the thread may be old, still I have encountered a similar problem and would be glad for some help. I am no engineer either, nor do I have a profound knowledge in programming.
I simulated a descendingstairlike intensitytime trace with some added noise. At certain points in time, the trace (which originally has a constant intensity) thus decreases by a certain, defined amount. I want to find the time point when an event occurred. Originally, I used a classical threshold method to find these events (therefore I always computed the difference in the intensity for every time point). When the noise increases, however, this does not work anymore and I get numerous false positives.
Thats why I used a Besselfilter (Matlab builtin function) to smooth my data.
It looks like this:
[b, a] = besself(8, 1.932 * 2 * pi * 2);
[numd, dend] = bilinear(b, a, (1 / (Framerate)));
J(:,1) = filter(numd, dend, J(:, 1)); %filter raw data
So I have an 8th order Besselfilter with the frequency Wo (1.932 * 2 * pi * 2) up to which the group delay is approximately constant. However, a (simulated) rectangular decrease in intensity is then curved and spread in time.
I would like to find out how much my original signal is in fact delayed due to filtering.
Is this frequency in "besself" equal to the cutoff frequency? Because I found a paper (the axon guide) where it is stated that for an 8th pole Besselfilter, the delay would be equal to 0.51/cutofffreq.
I then tried to use the function [gd,w] = grpdelay(8,1.932 * 2 * pi * bessel_freq,l) as stated above. What is the input argument l ?! This function (with l arbitrarily set to 128) returns several values, but I thought a Bessel filter would return a constant group delay.
Sorry for the long description. Thanks so much for helping me out. That would be great.
"Wayne King" wrote in message <h56kfu$1k1$1@fred.mathworks.com>...
> Hi David, the group delay is giving you an array (vector) because of what Rune explained: the phase response of a filter is a function of frequency. If you input a signal, which is a superposition of sinusoids through a filter, each sinusoidall component of the signal will be delayed (phase shifted) by a different amount in general. This is what grpdelay is telling you by outputting a vector.
>
> As a simple example of the special case of constant group delay, consider the following:
>
> d = fdesign.lowpass('Fp,Fst,Ap,Ast',1000,1500,1,60,10000);
> % Lowpass filter with passband edge frequency 1 kHz, stopband freq 1.5 kHz
> % passband ripple 1 dB, and 60 dB of attenuation. Sampling freq is 10 kHz
> Hd =design(d,'equiripple'); %FIR equiripple filter with linear phase
>
> The above filter (contained in Hd) has linear phase, which means the group delay will be a constant. To see this type
>
> grpdelay(Hd)
> %note we just plotted it in normalized frequency
>
> The delay is 21.5 samples which translates to 21.5*(1/10000) seconds because the sampling rate is 10 kHz. In this special case, each frequency is delayed by the same amount (although that amounts to a different phase shift for each frequency). Let's see how this filter acts on a simple 250 Hz sine wave input.
>
> dt =1/10000;
> t =0:dt:1dt;
> x= cos(2*pi*250*t);
> y = filter(Hd,x);
> plot(t(100:200).*1000,x(100:200),'k')
> hold on;
> plot(t(100:200).*1000,y(100:200),'b')
> axis([11 16 1.1 1.1]);
> xlabel('msec');
> legend('Input','Output');
>
> Note that the output is delayed by 2.2 msec as shown in the group delay. Since you are using an IIR filter (Butterworth) design, you will not have a constant group delay.
>
> Using the filter specifications object created in the first example, design a Butterworth filter:
>
> Hd1 = design(d,'butter');
> grpdelay(Hd1)
>
> So in this case you have to figure out how much the filter will phase shift (or delay) the frequency you are interested in. But the delay (in seconds) will be different for each frequency in general.
>
> Hope that helps,
> wayne
>
> David Aliaga <adapt_robot_lab08@yahoo.co.jp> wrote in message <32216228.8896.1249257863785.JavaMail.jakarta@nitrogen.mathforum.org>...
> > Thank you very much for the reply.
> >
> > I actually tried the Group delay, but it gives me an array not a single number. Now, I dont understand the meaning of the values of this array (cause they dont even remotely look like the correct delay) and also, I build a filter with a cutoff freq as parameter so why the delay would be in relation to other freqs?? I am confused about this.
> >
> > I will appreciate help on this.
> >
> > Kansai
