From: Xplosiv166 on 3 Nov 2009 16:59 >Xplosiv166 wrote: >>> On 3 Nov, 19:15, "Xplosiv166" <andrew_...(a)blueyonder.co.uk> wrote: >>>> Hi, >>>> >>>> I am looking to implement the following filter in either C, C#.Net or >>>> Visual Basic.Net. >>>> >>>> Type: =A0 =A0 =A0 =A0 =A0 =A0 =A0  Low Pass FIR >>>> Sampling Frequency:  480Hz (10Bit ADC Values from a microprocessor) >>>> Number of TAPs: =A0 =A0  51 >>>> Cutoff frequency: =A0 30Hz >>>> Window: =A0 =A0 =A0 =A0 =A0 =A0  Kaiser >>>> >>>> Basically this is a filter that somebody has proved using LabView and >> I >>>> need to write a similar filter in the either of the above languages. >>> If you need to replicate what others have already done in LabView, >>> the main concern is to get hold of a copy of the filter coefficients >>> that whoever have shown to work in the application. >>> >>> Once you have the coefficients, the filer itself is a simple loop >>> (pseudo code inspired by matlab): >>> >>> x =3D vector of N input samples >>> y =3D zeros(N+50); >>> h =3D 50 filter coeffficients >>> >>> for n=3D0:(N1+50) >>> for k =3D 0:50 >>> y(n)=3D y(n)+h(k)*x(nk); >>> end >>> end >>> >>> Don't take this too literally  I have ignored end effects, proof >>> reading and testing. >>> >>> However, once you have the filter coefficients h, the filter is >>> only marginally more complicated than shown. No need for FFTs or >>> IFFTs. >>> The FFT / IFFT pair speed computations up in offline applications, >>> but tend to complicate matters in online applications. They are >>> convenient, but not essential. >>> >>> Newbies can just stick with the simple loop like above. The main >>> problem with fixedpoint arithemtic will likely not be speed, but >>> numerical inaccuracy issues. >>> >>> Rune >>> >> >> Hi Rune, >> >> Thank you for you response it was very helpful. >> >> Question is the window in this case Kaiser part of the filter coefficients >> ? or is it part of the filter calculation loop (like in you example above) >> >> Also how hard would it be for me to design the above filter myself? I >> don't have any design tools although I think i have a students copy of >> Matlab 6.5 somewhere around although this would be no good for commercial >> applications. >> >> As i am not sure if I can actual get the coefficients, the filter does not >> have to be a perfect match to the one above. >> >> Also Can somebody please explain ((if they have time) why one would use a >> window and why would you use a Kaiser window specifically? > >The shaping window will usually be part of the given coefficients. The >capculations will certainly be done that way. You can ask when you get >the coefficients whether they have been windowed or not. > > From what you wrote, the filter was designed according to the "windowed >sinc" method. The choice of window sets the stopband attenuation, >passband ripple, and bandedge sharpness. More sophisticated windows >improves the first two and worsens the last. A few more taps get that >performance back. > >A window increases the stopband attenuation > >If, in the end, you need to derive the coefficients yourself, ignore all >that and use a filterdesign program that iteratively calculates optimum >coefficients with whatever cutoff sharpness, stopband attenuation, and >passband ripple is specified. You can use a free trial version of >ScopeFIR form http://www.iowegian.com/ to calculate the coefficients. > >A lowpass with a cutoff frequency that is such a small fraction of the >sample frequency is best done with an IIR unless there is a particular >reason to use an FIR filter. Was that considered? > >Jerry > >Engineering is the art of making what you want from things you can get. >����������������������������������������������������������������������� > Hi Jerry, Thank you for your response. The person who designed the filter supposedly knew what they were doing, but i am not convinced as they seem not to be able to supply me with the coefficients or the Kaiser Beta value used so that i could at least have a fighting chance at designing it myself. The signal I am looking at is between 1 and 6 Hz pulses, but as the hardware has limited filtering there is allot of mains (50Hz as i am in the UK) noise and the harmonics of and over that there is allot of low amplitude high frequency noise. I have tested the filter mentioned above in LabView and it seems to work well but cannot access the filter design it's self as I am viewing it through a LV GUI. >A lowpass with a cutoff frequency that is such a small fraction of the >sample frequency is best done with an IIR unless there is a particular >reason to use an FIR filter. Was that considered? I originally was using a very basic single pole IIR filter which worked but not well enough, I am no DSP engineer but it is looking more and more like i will need to design the filter myself, on a plus point i have Matlab 6.5 and simulink working which i can use to calculate the coefficients using the filter designer if only i knew what i was doing. This is a very basic mspaint attempt at drawing the signal and before and after filtering http://andy166.pwp.blueyonder.co.uk/Signal.jpg Is there any example code written in C/C++ that uses an array of coefficients and calculates the output from an array of inputs that I can use (i.e. the FIR filter)? Then i can test my filters out. Thanks again for your/every bodies help on this, Xplosiv166
From: Jerry Avins on 3 Nov 2009 17:33 Xplosiv166 wrote: ... > The person who designed the filter supposedly knew what they were doing, > but i am not convinced as they seem not to be able to supply me with the > coefficients or the Kaiser Beta value used so that i could at least have a > fighting chance at designing it myself. He couldn't assess the adequacy of the filter without testing it at least to th point of producing a frequenctresponse curve. That requires knowing the values of the windowed coefficients. If he never knew them, then his design is by estimation and untested. > The signal I am looking at is between 1 and 6 Hz pulses, but as the > hardware has limited filtering there is allot of mains (50Hz as i am in the > UK) noise and the harmonics of and over that there is allot of low > amplitude high frequency noise. I have tested the filter mentioned above in > LabView and it seems to work well but cannot access the filter design > it's self as I am viewing it through a LV GUI. The links I provided can get you the coefficients and a response plot. >> A lowpass with a cutoff frequency that is such a small fraction of the >> sample frequency is best done with an IIR unless there is a particular >> reason to use an FIR filter. Was that considered? > > I originally was using a very basic single pole IIR filter which worked > but not well enough, I am no DSP engineer but it is looking more and more > like i will need to design the filter myself, on a plus point i have Matlab > 6.5 and simulink working which i can use to calculate the coefficients > using the filter designer if only i knew what i was doing. It should be no trick to design an eighthorder FIR Chebychev filter that will do your job very well. The aJava ap is set for 8 KHz sample rate. Just ratio the cutoff you want and it serve. > This is a very basic mspaint attempt at drawing the signal and before and > after filtering > > http://andy166.pwp.blueyonder.co.uk/Signal.jpg > > Is there any example code written in C/C++ that uses an array of > coefficients and calculates the output from an array of inputs that I can > use (i.e. the FIR filter)? Then i can test my filters out. I don't have one. It shouldn't be hard to write once a program gives you the coefficients. Jerry  Engineering is the art of making what you want from things you can get.
From: Richard Dobson on 3 Nov 2009 17:46 Xplosiv166 wrote: ... > > http://andy166.pwp.blueyonder.co.uk/Signal.jpg > > Is there any example code written in C/C++ that uses an array of > coefficients and calculates the output from an array of inputs that I can > use (i.e. the FIR filter)? Then i can test my filters out. > See if you can find a copy of the book "Introductory Digital Signal Processing" by Lynn and Fuerst: http://www.amazon.co.uk/IntroductoryDigitalSignalProcessingdisk It has (to my nonspecialist eye) very clear explanations, and example code. The first edition (which I have and still refer to) used Basic and Pascal, the second edition uses C instead of BASIC. There is a whole lot of code in opensource audio/music tools such as Csound (including code to make Kaiser windows; widely used in phase vocoders). A filter is a filter, and it doesn't matter if your own application isn't "musical" as such; the requirements are much the same. Richard Dobson
From: Fully Half Baked on 3 Nov 2009 20:56 I'm sure there's an online filter calculator that gives out a C style difference equation but I can't remember which one it is. I have a free program called WinFilter that gives out C code. I'm not sure how good it is for designing filters but it can give you an idea of how to use coefficients in your code. Stephen Smiths book http://www.dspguide.com/pdfbook.htm is pretty good for a beginner and includes pseudo code in basic (whatever that is).
From: Xplosiv166 on 5 Nov 2009 06:22 >I'm sure there's an online filter calculator that gives out a C style >difference equation but I can't remember which one it is. I have a >free program called WinFilter that gives out C code. I'm not sure how >good it is for designing filters but it can give you an idea of how to >use coefficients in your code. >Stephen Smiths book http://www.dspguide.com/pdfbook.htm is pretty good >for a beginner and includes pseudo code in basic (whatever that is). > Hi all, Thank you for your help, i will try what you have suggested and see how i get on Xplosiv166
First

Prev

Pages: 1 2 Prev: Seeking a simple audio energy detection algorithm Next: Boot Flash for TS201 