DSPRelated.com
Forums

[NEWBIE question] How do I filter a digitized signal

Started by Richard Owlett August 13, 2004
Rick Lyons wrote:
> On Fri, 13 Aug 2004 16:43:51 -0500, Richard Owlett > <rowlett@atlascomm.net> wrote: > > (snipped) >
-- snip --
> I don't know about Scilab, but MATLAB has a > "filter" command that's used to filter some > time-domain "x" variable (a list of input sample values) > using a filter that's defined by its feedforward and > feedback coefficients. For nonrecursive FIR filters, > the feedforward coefficients needed by MATLAB are the > FIR filter's coefficients (h), and the feedback > coefficients needed by MATLAB turn out to be a simple > single value of one. In MATLAB language, filtering > an input sequence, x, with an FIR filter looks like: > > Output = filter([h0,h1,h2,h3],1,x); > > Maybe Scilab is similar to the above, I don't know. > > That above MATLAB command implements my Eq. (6-1) on > page 213. [Please note that there is a "typo" in Eq. > (6-1) that I'm desperately trying to get the > publisher to correct. In Eq. (6-1) the term > "h(4)x(n-4)" should NOT be there. Please cross out > that h(4)x(n-4) term.] > > For an IIR filter, my Eq. (6-2), on page 214, gives the > necessary computations to implement the IIR filter in > Figure 6-3. In MATLAB language, filtering > an input sequence, x, with the Figure 6-3 IIR filter > looks like: > > Output = filter([b(0),b(1),b(2),b(3)],[1,-a(1),-a(2),-a(3)],x); > > No, the minus signs for the above a(k) feedback coefficients > are not a mistake. The minus signs are necessary because > of the way MATLAB expects the feedback coefficients to > be defined. >
-- snip --
> [-Rick-] > > Where am I? > In the Village. > What do you want? > Information. > Whose side are you on? > That would be telling ... We want Information. > You won't get it. > By hook or by crook ... we will. > Who are you? > The new Number Two. > Who is Number One? > You are Number Six. > I am not a number ... I am a free man! > (Mocking laughter) >
To do this in SciLab you first define a linear system (syslin), then you get its response with 'flts'. Type 'apropos syslin' and 'apropos flts' for help; for the FIR case (here a raised-cosine): H_fir=syslin(0.0001, 0.01*poly(1 - cos(2*%pi*(0.01:0.01:0.99)), 'z', 'coeff'), poly([zeros(1,98) 1], 'z', 'coeff')); For the IIR case, a 2nd-order whomped-up lowpass: d=0.95; th=0.05; H_iir=syslin(0.0001, abs(1-d*exp(%i*th))^2*poly([0 0], 'z'), poly(d*[exp(%i*th) exp(-%i*th)], 'z')); Then you can plot their responses: clf; plot2d(flts(ones(1,200), H_iir)); plot2d(flts(ones(1, 200), H_fir)) Its more formalized than Matlab so it's harder to do something little like this, but it should take longer to get ungainly as your application grows. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com