Software 2nd order Low Pass Filter algorithm and FFT

Dear reader
Does any one have a algorithm that functions as a second order Low Pass Filter LPF which specifies the parameters in terms of Cutoff frequencies and phase shifts?.

===============================

I ask this question for the following reason, commends are welcome if I make a mistake
I want to analyses a line voltage and line current with FFT by sampling them at the same time in two FFT sample arrays.
I have done some experiments with FFT in excel en saw interesting phenomenons which are

  • FFT Bin one generates amplitude and phase of a zero harmonic sinusoidal under the condition that the FFT Bin frequency spacing is close to or exactly the sinusoidal frequency of the signal.
  • If the signal is not zero harmonic sinusoidal but constant the other bins generate the harmonics which allow to calculate the THD of the signal.
  • By measuring the current and voltage at the same time, also the phase difference between the two is calculated from the difference between the FFT signals.
  • For FFT no peak detection or other synchronizations mechanisms are needed to calculate the peak current and voltage phase and THD. The only thing needed is a accurate frequency of the first harmonic and sampling both signal at the same time
    .

Consider the frequency of the first Bin/harmonic unknown but between 40 ... 70 Hz. By starting the sample rate corresponding with the 40Hz FFT bin we can scan the 40..70Hz band for a maximum amplitude signal which ones found corresponds with the net frequency of the signal we measure. Scanning is done by adjusting the timer interrupt of a 16bit timer of a controller which runs on 16Mhz with a timer prescaler equal to 1. This timer interrupt service routine reads the voltage and current signals and the scan resolution must be high.

Assuming this method is correct(i think i am) we can 1) measure accurate the frequency of a net signal and following 2) compute the FFT and the corresponding amplitudes, phase and THD of a signal without the need for peak detectors and or synchronization mechanisms.

To do a scan of the input between 40..70 Hz preferably is done on a clean sinusoidal without harmonics. For that reason I need a second order filter. Preferably is done means that its nice to have but not a must.

i hope some can help me with a filter algorithm and confirm whether or not i'm correct with my description.

Thanks Oscar Goos

I’ve no idea , but there are lots of hits for this sort of stuff on google . Gut feeling is this may be too hard for Arduino too

I darent ask why you want to do it ...

You can use either an IIR or FIR low pass filter. Some web design pages will actually write the code for you.

Examples of code.

On line design calculator

hammy:
I’ve no idea , but there are lots of hits for this sort of stuff on google . Gut feeling is this may be too hard for Arduino too

I darent ask why you want to do it ...

Thanks at least for responding

From the OP I deduce that the signal being processed is a sinusoid with some distortion. Since you are only interested in the fundamental you don't need the Fourier coefficients for all the other harmonics so there is no point in computing the complete Fourier Transform. An FFT takes approx (N Ln N) operations (1) but a single coefficient will take just N operations thus saving a factor of (Ln N) . If N is just 64 then you will save a factor of 6 !

(1) An operation is this case is a complex multiplication and a complex addition.

Two points.

  1. As per jremington's post above, there are online resources for calculating filter coefficients and producing code. That said, a digital filtering scheme will have the same aliasing problems as the FFT, so if your intent is to keep high harmonics from aliasing back to the fundamental frequency it will need to be done in the analog domain prior to the ADC.

  2. Statement 4 of the original post doesn't seem quite right. It suggest that the advantage of the approach is that synchronization with the source signal is not necessary, but then goes on to describe what is essentially synchronization in the frequency (sampling) domain. It's not apparent that this has made the problem any more tractable.

  1. The AVr based Arduinos are designed for control and not for signal processing.

  2. There are others which do have support for DSP in the same price range

  3. A low pass filter of any order (reasonable) is so cheap, simple and easy to do IN HARDWARE that I can't see any point in doing in software.

  4. Reading between the lines I think you should look at a band pass filter again a very simple thing to do.

Mark