Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help with filtfilt

280 views
Skip to first unread message

Gregory

unread,
Sep 3, 2009, 2:27:04 PM9/3/09
to
Hi. I have some problem with using the filtfilt function for my signal processing. I created a bandpass filter thats 10th order Butterworth in the Filter design tool. I then saved the output as a .mat file so that it creates a dfilt.df2sos item in the workspace everytime I load the .mat file.

Now how can I use the filtfilt function on my filter since you need both the b and a parameters for filtfilt. Are they any of the following parts of the filter object:
ScaleValues
States
sosMatrix?

Thanks and sorry if it seems like a trivial question.

Wayne King

unread,
Sep 3, 2009, 3:11:02 PM9/3/09
to
"Gregory " <gregory...@gatech.edu> wrote in message <h7p1po$1bv$1...@fred.mathworks.com>...

Hi Gregory, it's not a trivial question. filtfilt() does not currently work on filter objects (unlike filter()), so if you have created a dfilt.df2sos object. You want to extract the numerator and denominator coefficients and use those in filtfilt(). If you are using filtfilt(), you may just want to create the filter coefficients as numerator and denominator vectors to begin with, but let's just assume that you have a dfilt.dfsos filter object. First, I'll create a dfilt.df2sos object:

[z,p,k] = butter(9,300/500,'high');
[sos,g] = zp2sos(z,p,k); % Convert to SOS form
Hd = dfilt.df2sos(sos,g); % Create a dfilt object

% Now you can use sos2tf()

[B,A]=sos2tf(Hd.sosMatrix,Hd.Scalevalues);

% compare
fvtool(B,A)
% with
fvtool(Hd)

Hope that helps,
wayne

Andy Daubenspeck

unread,
Sep 8, 2009, 4:49:02 PM9/8/09
to
"Gregory " <gregory...@gatech.edu> wrote in message <h7p1po$1bv$1...@fred.mathworks.com>...

Wayne's response to this timely (for me!) question helped me also, but the problem I am having is that the conversion of the sos form to the transfer function form for my 6th order bandpass design provides a similarly unstable filter that computing the [b,a] values directly provides. Is there no way to use the nice looking filter provided by the [z,p,k] design route to a filtfilt process? Thanks for any help with this.
Andy

Daniel Wang

unread,
Dec 30, 2010, 6:07:04 PM12/30/10
to
"Andy Daubenspeck" wrote in message <h86fvu$ge9$1...@fred.mathworks.com>...

Hi, Andy. Have you solved this problem yet? I am having the same problem right now. I tried to follow the instructions on http://www.mathworks.com/support/solutions/en/data/1-BJ2YFF/index.html?product=SG&solution=1-BJ2YFF, but I didn't quite understand step 2. Do you have any idea?

Sudip

unread,
Jan 4, 2011, 5:57:07 PM1/4/11
to
Hello,

I would like to construct a lowpass filter, with low pass cutoff frequency of (1/45.66)per hr. I am analyzing a time series of 4224 points and the data is sampled per hour. I used a basic butter worth filter of 5th order and then used filtfilt coz I dont want any phase delay. But when I use the fvtool command I dont see the
the desired frequency response. I did normalize the frequency with the sampling frequency of 0.5 per hour. Can any one please help me.

Regards,
Sudip

Wayne King

unread,
Jan 4, 2011, 6:48:08 PM1/4/11
to
"Sudip" wrote in message <ig08k3$fpi$1...@fred.mathworks.com>...

Hi Sudip, if you use butter() to design your filter, that function only accepts normalized frequencies between 0 and 1 where 1 is actually 1*pi radians per sample. So you should multiply your frequency in cycles/hour by 2:

2/45.66

which is really (2*pi)/45.66 radians/sample, that is your Wn input to butter(). I'm assuming I read your notation correctly and your frequency is 1 cycle per 45.66 hours.

Hope that helps,
Wayne

Sudip

unread,
Jan 5, 2011, 1:27:05 PM1/5/11
to
"Wayne King" <wmki...@gmail.com> wrote in message <ig0bjo$s3v$1...@fred.mathworks.com>...

Thank you Wayne.
I tried what you suggested. But I was wondering that earlier I used Wn=flp/fnq (to normalize the frequency)
where flp=1/45.66 cycles per hour, and fnq= Nyquist frequency =.5 cycles/hr(my time series is sampled every hour). So normalized frequency itself was Wn=(1/45.66)/.5=(2/45.56) which is the same frequency you suggested. Am I reading you correctly.

Sudip

Wayne King

unread,
Jan 5, 2011, 1:37:04 PM1/5/11
to
"Sudip" wrote in message <ig2d5p$19g$1...@fred.mathworks.com>...

Hi Sudip, yes that is correct. I was being very explicit, just in case. Are you saying that:

[b,a] = butter(5,2/45.56);
fvtool(b,a)

Does not produce your expected magnitude response?

Wayne

0 new messages