1

Initially I have an array of time and an array of voltage and I have applied FFT and converted that time domain into frequency domain.After applying FFT I got an array of frequencies. Now I have cut off frequency and I need to implement Low pass filter on the same. I need to do this using JAVA. Could someone please refer me if there is any open source available or any idea of implementing the same. Any references that would be implemented using frequency values and cut off frequency would help.

I am completely new to this topic so my approach of question might be little weird. Thanks in advance for support!!!

Dinesh
  • 149
  • 1
  • 3
  • 12
  • http://stackoverflow.com/questions/4026648/how-to-implement-low-pass-filter-using-java – javajon Jul 09 '14 at 03:02
  • I have seen this post. But it didn't resolve my requirement. – Dinesh Jul 09 '14 at 03:25
  • I posted a full method for a fourier lowpass filter here: http://stackoverflow.com/questions/4026648/how-to-implement-low-pass-filter-using-java/33510757#33510757 – Mark Nov 05 '15 at 01:10

1 Answers1

2

Since you already have a array with the FFT values, you can implement a very crude low pass filter by just setting those FFT coefficients that correspond to frequencies over your cut-off value to zero.If you need a nicer filter you can implement a digital filter or find an LPF implementation online and just use that.

EDIT: After computing the FFT you don't get an array of frequencies, you get an array of complex numbers representing the magnitude and phase of the data.You should be able to know what frequency each and every complex number in the array corresponds to because the FFT result will correspond to evenly spaced frequencies ranging from 0 to f_s, where f_s is the sampling frequency you used to get your data.

A useful exercise might be to first try and plot a frequency spectrum, because after plotting it, it will be clear how you can discard high frequencies thus realising a LPF.This slightly similar post might help you: LINK

EDIT: 1) First you need to find the sampling frequency (f_s) of your data, this is the number of samples have taken every second.It can be computed using f_s = 1/T, where T is the time interval between any two consecutive samples in the time domain.

2) After this you divide f_c by f_s, where f_c is the cut-off frequency to get a constant k.

3) You then set all COMPLEX numbers above index ( k times N) in your array to zero, where N is the number of elements in your array, simple as that, that will give you a basic Low pass filter (LPF).

Rough, indicative (pseudo)code below:

Complex[] fftData = FFT(myData);
int N = fftData.Length;

float T = 0.001;   
float f_c = 500;   //f_c = 500Hz
float f_s = 1/T;   //f_s = 1000Hz

float k = f_c/f_s;
int index = RoundToNextLargestInteger(k * N);

//Low pass filter   
for(int i = index; index < N; index++)
   fftData[i] = 0;

The fftData you receive in your case will not already be in the form of elements from the Complex class, so make sure you know how your data is represented and which data elements to set to zero.

This is not really a good way to do it though as a single frequency in your data can be spread over several bins because of leakage so the results would be nasty in that case.Ideally you would want to design a proper digital filter or just use some software library.So if you need a very accurate LPF, you can go through the normal process of designing analog LPF and then warping it to a digital filter as discussed in THIS document.

Community
  • 1
  • 1
KillaKem
  • 995
  • 1
  • 13
  • 29
  • So, A simple for loop running through entire array of frequencies and if some frequency value in array goes beyond cut off frequency I could convert it to 0.00 – Dinesh Jul 10 '14 at 18:33
  • Am I correct? or you are explaining something apart from this? Thanks!! – Dinesh Jul 10 '14 at 18:34
  • Thanks KillaKem, That helps. My concern here is I have no idea of FFt and Low pass filters. I have started working on these recently. I have a time values in an array and I found an FFT algorithm to transform into frequency domain [link] http://www.wikijava.org/wiki/The_Fast_Fourier_Transform_in_Java_%28part_1%29. I have passed real values as input of time for the above algorithm and passed an empty array for imaginary part. Now I need to implement Low pass filter on the frequency values obtained(Here I will have cut off freq) and then I need to convert those frequencies back to time domain – Dinesh Jul 11 '14 at 00:57
  • I think i have made my point clear. Could you please guide me how to deal Low pass filter in this case. In the above mentioned algorithm itself I could implement Inverse transform. So I am looking for Low pass Filter algorithm suitable for my need. – Dinesh Jul 11 '14 at 00:59