JonHub / Filters

A realtime digital signal processing (DSP) library for Arduino
Apache License 2.0
174 stars 64 forks source link

Filters - output #2

Open johnrod956 opened 6 years ago

johnrod956 commented 6 years ago

I'm not sure if I am setting it up correctly but if I set a low pass filter frequency at 100 (Hz). The 100 Hz should be the cutoff frequency correct? Now if I use the output function of my filter and print the value... should I be seeing a value of zero if my input frequency is over 100 Hz?

JonHub commented 6 years ago

The filters are designed to behave identically to their electronic counter parts (single-pole RC, and two pole Bessel/Butterworth filters). Essentially "Filters" simulates these circuits in real-time digital embedded. You can lean more about the filter behavior (in terms of frequency response) by checking into standard single- and two-pole filters.

Since the filters are single-pole and two-pole, they are not infinitely sharp in terms of frequency cutoff. So, you will still see some output at an input frequency 100 Hz, or even 1000 Hz (though dramatically attenuated).

From the user perspective, the frequency you supply is the “corner frequency,” which is the standard number used to define a filter. The signal is attenuated by 3 decibels at the corner frequency, which is half the power (or 1/sqrt(2) of the magnitude).

So, in your case, if you enter a corner frequency of 100, then your filter will output about 71% the maximum value at that frequency. Keep in mind that you need to updated the filter FREQUENTLY - many more times than your corner frequency, per second, probably closer to 1000x (or more)- for it to work

Since the filters are recursive (they “time-step” to calculate the next value, so the updates need to happen at a scale that is faster than big the signal, or filter). This is typically easy to achieve, but can eat up some resources for the DSP.

If you are stepping too infrequently, the single-pole filters will remain stable, and the two-pole filters have a “check,” so they remain numerically stable, but the output will not be correct.

Hope this helps.