- From: Sandy Pond <sandy_pond_at_myrealbox.com>
- Date: Thu, 10 Mar 2005 21:35:38 -0500
On Thu, 2005-03-10 at 18:38 -0500, Daniel Nilsson wrote: > On Tue, Mar 08, 2005 at 10:07:15AM -0500, Sandy Pond wrote: > > On Sun, 2005-03-06 at 22:26 -0500, Daniel Nilsson wrote: > > > > > > Thanks, I have been looking at your code trying to figure out if you > > > are implementing an FIR or IIR filter ? Or is it some other kind of > > > filter ? Sorry for the basic questions here... > > > > It uses trapezoidal integration. The proof is rather easy but I can't > > seem to find something like it by googling around. Therefore, I can't > > give you a pointer. If you want I'll write it up and post it. It's a > > home made algorithm so I don't know what to call it, but I'm certain > > someone else might know (perhaps TIR for Trapezoidal Integrated Response > > filter). I put it together in the '80s when I was doing digital > > simulations then later modified it to use integer math for > > microprocessors with A/D. > > I got a chance to test your filter code on some sampled data > yesterday. It works really well actually, the code is fast compared to > FIR filters (filtered 65536 samples in 2.2ms on my machine) and produces > a sharp low pass filter. I think I'll try to use your filter in my > application, looks like this will fir very well what I needed. Thanks > for putting this together ! > > > If you want to run your data though the filter and your data is in a > > file then just use the program I posted and modify it for your cutoff > > frequency and use fopen/scanf to read in your raw data stream. Warning: > > the data needs to be integers that are less than 65536 (short int). The > > routine was written for A/D counts. > > So the next question is then where I put in the filter... What I did > what just scale my samples from float by a factor (10000 in my case ) > so that I could treat them as unsigned short int (16bits). My A/D > converter is a 16 bit converter as well, but I can't quite figure out > from the Comedi documentation if this means I can run the samples > directly from the read() command through the filter or if I first need > to do the comedi_to_phys() function ? How is the sign information > stored ? Well. Normally, in all the equipment I've ever used, D/A and A/D converters read and write unsigned integers. For bipolar ranges the "0 Volts" is usually half range. Example, for a 16 bit A/D. Full range would be 2^16 or 65536 counts. If the full scale range of the A/D is set to 0/+5 Volts, then a count of 0 would represent 0 Volts and a count of 65535 would represent +5 Volts. If the range is set to -5/+5 Volts, then a count of 0 would be -5 Volts and a count of 65535 would be +5 Volts. Then half range or 32767 counts would represent 0 Volts. The routine I attached was written to operate on the raw A/D or D/A counts, therefore, is not applicable for signed integers. What you want to do is run the raw 16 bit A/D samples through the filter before they are converted to floats. If you convert to floats then back to integers you are losing accuracy in your data. I'm new to comedi, but I have a lot of experience in this field. Actually, I'm trying to find out what hardware I want to get for my embedded application and I want to use comedi for the first time. Maybe Bernd Porr <BerndPorr_at_f2s.com> can assist you, but from the documentation: http://www.comedi.org/doc/x403.html#FIRSTPROGRAM Section 3.2 says that samples are returned as unsigned integers (0-65535). And "include/linux/comedi.h" defines the data returned as: typedef unsigned int lsampl_t; So just cast the data to (unsigned short int) and feed those through the low_pass_filter: data[i] = low_pass_filter((unsigned short int) data[i], mylpf); And then use comedi_to_phys() on the result to get the float volts. This will preserve the full accuracy of the A/D. BTW thanks for the question because when I looked at the code I saw a bug. I forgot to use and unsigned int for the variable "dy". This is a bug ... but hard to trigger. Attached is the corrected code. Regards
Attachments
- text/x-csrc attachment: stored
Received on 2005-03-11Z02:35:38