DSPRelated.com
Forums

Matlba butterworth IIR filter implementation - sample by sample filtering basis

Started by Dinuka June 16, 2012
On Monday, June 18, 2012 3:16:25 PM UTC+10, Tim Wescott wrote:
> On Sun, 17 Jun 2012 18:11:58 -0400, robert bristow-johnson wrote: > > > On 6/17/12 4:52 PM, Tim Wescott wrote: > >> > Well, if you feel bound and determined to do it with vectors, here's > >> > the > >> example (with Scilab's response) > >> > >> -->H = syslin('d', poly((0.0001/3) * [1 1 1], 'z', 'coeff') / > > > > > > > >> poly ([0.9859 -1.9858 1], 'z', 'coeff')) > > > > > >> H = > >> > >> 2 > >> 0.0000333 + 0.0000333z + 0.0000333z > >> ----------------------------------- > >> 2 > >> 0.9859 - 1.9858z + z > >> > >> > > > > well, i can't tell with the numerator, but looking at the denominator it > > is apparent that Scilab differs from MATLAB regarding convention of > > ordering the coefficients of a polynomial. > > > > MATLAb would say it's [1 -1.9858 0.9859]. > > > > which is, of course, ass-backwards. > > Unless the polynomial is in z^-1. > > -- > Tim Wescott > Control system and signal processing consulting > www.wescottdesign.com
Hi All, The issue I have is, I want to filter an signal sample by sample - not the whole signal at once. I use the following approach when I used the FIR filters. I got the FIR coefficients using 'firpm' (Parks-Mcclellam optimim eqiripple filter design function) But I had to use 200 length filter to get high filter respose. fl = 200; q=fl+1; % Length of the filter f=[0 2*1*fc/fs 2*1.2*fc/fs 1]; a=[1 1 0 0]; % filter response specification h=firpm(fl,f,a); % signal filtering at sample k vec = [vec(2:q) sig(k)] lpf_out=fliplr(h)*vec'; Now I want to use an IIR filter to filter a signal sample by sample. Can someone advice on this issue? Thanks.
On Mon, 18 Jun 2012 00:19:25 -0700, Dinuka wrote:

> On Monday, June 18, 2012 3:16:25 PM UTC+10, Tim Wescott wrote: >> On Sun, 17 Jun 2012 18:11:58 -0400, robert bristow-johnson wrote: >> >> > On 6/17/12 4:52 PM, Tim Wescott wrote: >> >> > Well, if you feel bound and determined to do it with vectors, >> >> > here's the >> >> example (with Scilab's response) >> >> >> >> -->H = syslin('d', poly((0.0001/3) * [1 1 1], 'z', 'coeff') / >> > >> > >> > >> >> poly ([0.9859 -1.9858 1], 'z', 'coeff')) >> > >> > >> >> H = >> >> >> >> 2 >> >> 0.0000333 + 0.0000333z + 0.0000333z >> >> ----------------------------------- >> >> 2 >> >> 0.9859 - 1.9858z + z >> >> >> >> >> >> >> > well, i can't tell with the numerator, but looking at the denominator >> > it is apparent that Scilab differs from MATLAB regarding convention >> > of ordering the coefficients of a polynomial. >> > >> > MATLAb would say it's [1 -1.9858 0.9859]. >> > >> > which is, of course, ass-backwards. >> >> Unless the polynomial is in z^-1. >> >> -- >> Tim Wescott Control system and signal processing consulting >> www.wescottdesign.com > > Hi All, > > The issue I have is, I want to filter an signal sample by sample - not > the whole signal at once. > > I use the following approach when I used the FIR filters. I got the FIR > coefficients using 'firpm' (Parks-Mcclellam optimim eqiripple filter > design function) But I had to use 200 length filter to get high filter > respose. > > fl = 200; q=fl+1; % Length of the filter f=[0 2*1*fc/fs 2*1.2*fc/fs 1]; > a=[1 1 0 0]; % filter response specification h=firpm(fl,f,a); > > % signal filtering at sample k vec = [vec(2:q) sig(k)] > lpf_out=fliplr(h)*vec'; > > Now I want to use an IIR filter to filter a signal sample by sample. > > Can someone advice on this issue?
I can and did! Why don't you go to the post where I showed you how to turn a transfer function into a difference equation, tell us what you don't get, and we'll go from there! If you can't get from a bit of math to Matlab code you may have a long row to hoe, though. -- Tim Wescott Control system and signal processing consulting www.wescottdesign.com
On 6/18/2012 12:19 AM, Dinuka wrote:
> On Monday, June 18, 2012 3:16:25 PM UTC+10, Tim Wescott wrote: >> On Sun, 17 Jun 2012 18:11:58 -0400, robert bristow-johnson wrote: >> >>> On 6/17/12 4:52 PM, Tim Wescott wrote: >>>>> Well, if you feel bound and determined to do it with vectors, here's >>>>> the >>>> example (with Scilab's response) >>>> >>>> -->H = syslin('d', poly((0.0001/3) * [1 1 1], 'z', 'coeff') / >>> >>> >>> >>>> poly ([0.9859 -1.9858 1], 'z', 'coeff')) >>> >>> >>>> H = >>>> >>>> 2 >>>> 0.0000333 + 0.0000333z + 0.0000333z >>>> ----------------------------------- >>>> 2 >>>> 0.9859 - 1.9858z + z >>>> >>>> >>> >>> well, i can't tell with the numerator, but looking at the denominator it >>> is apparent that Scilab differs from MATLAB regarding convention of >>> ordering the coefficients of a polynomial. >>> >>> MATLAb would say it's [1 -1.9858 0.9859]. >>> >>> which is, of course, ass-backwards. >> >> Unless the polynomial is in z^-1. >> >> -- >> Tim Wescott >> Control system and signal processing consulting >> www.wescottdesign.com > > Hi All, > > The issue I have is, I want to filter an signal sample by sample - not the whole signal at once. >
I think what you mean by this, and correct me if I'm wrong, you want a filter process that operates in a streaming fashion rather than in a batch mode. That is, you want a sample out for each sample in. If you're doing it in Matlab then you just have to keep a vector of all the states in the filter .. one way or another. Instead of using the "tools", why not just write it out? That really has little to do with filter design and much about implementation in code. Fred