On Wed, 11 Apr 2001, Olin Lathrop wrote: > > This sort of goes back to what the intent is. I don't really expect to > > see high frequency noise (but this may be way wrong on my part, of > > course). What I wanted to smooth out was variations in crank rotational > > speed (if any) caused by the cylinders firing. That might cause the > > readings displayed on the LCD to be unstable and/or inaccurate. So I > > guess it's intended as a ripple filter and not a HF noise filter, though > > on reflection I may need both. > > What you describe is high frequency noise in this context. You don't want > the display to jump around. In otherwords, you don't want to bother the > user with the high frequency content of the rotation speed, just the "trend" > over a few hundred milliseconds. That IS low pass filtering. The advantage > of expressing your problem in signal processing terms is that many people > have been there before. There are many well understood standard techniques > for achieving various results. Once you admit you have a signal processing > problem you tap into this. Guess it never occurred to me, really. I know squat about filters, as you have no doubt already noticed... > > then add that to the filter > > variable for "n" (maybe 32) samples, then I'd divide that (shift it, > > whatever) to get the average. > > That's very different from what I had in mind. You are back to a box filter > with this approach. I suggested a simple single pole low pass filter. If > FILT is the filtered value to update with a new reading and NEW is the new > reading, then a single pole filter is: > > FILT <-- FILT*(1-F) + NEW*F Man, here is where I run into a wall. I am totally unfamiliar with digital filtering techniques. What is F? Is it the inverse of the number of samples added to the accumulator? I keep thinking I can see how this works, but then I plug it into Excel and it doesn't work. Should've gone for that engineering degree. I've tried sample values in a spreadsheet using several formulas, including FILT-(FILT*(2^-N))+NEW*(N) FILT-(FILT*(2^-(1/N)))+NEW*(1/N) where FILT is the value to be updated, NEW is the accumulated value of the new reading, and N is the number of new readings that have been accumulated. None are making much sense. I suspect there's just something I have fundamentally misunderstood about what you're trying (valiantly) to explain to me. > F is the filter fraction. It is convenient to have F be 2**-N, like 1/8 or > 1/16. In that case multiplication by F becomes a right shift by N bits. > Multiplication by 1 - F is the original value right shifted N bits > subtracted from itself. Note that this type of filter is computationally > simple and only requires one state value. Smaller values of F produce more > filtering. Note that the filter never changes when F = 0, and there is no > filtering (filter output is always the most recent value) when F = 1. > > > Would that not have to be done to completion > > for each reading? In other words, any time I want to read RPM, I always > > have to wait n tach pulses before I can calculate the average, right? > > I would decouple the display update from the frequency calculation from the > pulse capturing. The pulse capturer maintains the total pulse period and > the number of pulses since the last conversion. The frequency converter > checks the pulse capture state periodically and does a conversion whenever > it finds at least one pulse has been captured. It filters the result and > maintains the Official Frequency. The display update runs 2 to 4 times per > second and writes the current Official Frequency to the display. That's pretty much what I've got now, really. On every iteration I do some other data collection and calculation, then average out the most recent 20 (could be more or less depending on available RAM) pulse widths, calculate the RPM from that, and display the lot. Aside from code size and speed (neither of which is an issue here), what would I gain by using the single-pole low pass filter? Dale --- The most exciting phrase to hear in science, the one that heralds new discoveries, is not "Eureka!" (I found it!) but "That's funny ..." -- Isaac Asimov -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu