Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Signal filtering and DELAY

Subject: Signal filtering and DELAY

From: David Aliaga

Date: 2 Aug, 2009 10:50:47

Message: 1 of 5

Greetings everyone.
This is my first message. I am not a DSP engineer but a programmer with a very limited knowledge of filters. I am writing in the hope that someone can help me with his/her expertise in the following problem:

I have a butterworth filter implemented in software.(C++) So far it works exactly the same as the functions: butter() and filter() in Matlab.
Therefore when I use butter with an order and a cuttoff freq it builds a filter, and then I can use it with a signal with noise and obtain and noise-free signal.

My question is:
I would like to know of a method to calculate the "delay" between the original signal and the filtered one. As far as I understand this must be a value in seconds.

So far I have found the function groupdelay() but I dont think this is what I am looking for. It gives me a matrix when I am only searching for a single value(the delay for a particular filter designed with a particular
cuttoff freq is only a number)

Can anyone point me where to look?

I will be very grateful for your help.

Subject: Signal filtering and DELAY

From: Rune Allnor

Date: 2 Aug, 2009 11:20:41

Message: 2 of 5

On 2 Aug, 12:50, David Aliaga <adapt_robot_la...@yahoo.co.jp> wrote:
> Greetings everyone.
> This is my first message. I am not a DSP engineer but a programmer with a very limited knowledge of filters. I am writing in the hope that someone can help me with his/her expertise in the following problem:
>
> I have a butterworth filter implemented in software.(C++) So far it works exactly the same as the functions: butter() and filter() in Matlab.  
> Therefore when I use butter with an order and a cuttoff freq it builds a filter, and then I can use it with a signal with noise and obtain and noise-free signal.
>
> My question is:
> I would like to know of a method to calculate the "delay" between the original signal and the filtered one. As far as I understand this must be a value in seconds.
>
> So far I have found the function groupdelay() but I dont think this is what I am looking for. It gives me a matrix when I am only searching for a single value(the delay for a particular filter designed with a particular
> cuttoff freq is only a number)
>
> Can anyone point me where to look?

The group delay is probably what you are looking for.
The delays through filters are determined by the phase
response of the filters, and generally vary with
frequency. Which is why you can't find a single number.

Rune

Subject: Signal filtering and DELAY

From: David Aliaga

Date: 3 Aug, 2009 00:03:53

Message: 3 of 5

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

Subject: Signal filtering and DELAY

From: Wayne King

Date: 3 Aug, 2009 12:17:02

Message: 4 of 5

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:1-dt;
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

Subject: Signal filtering and DELAY

From: chile1987

Date: 7 Feb, 2013 18:21:06

Message: 5 of 5

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 descending-stair-like intensity-time 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 Bessel-filter (Matlab built-in 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 Bessel-filter 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 Bessel-filter, the delay would be equal to 0.51/cutoff-freq.
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:1-dt;
> 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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us