I am trying to accomplish applying an FFT algorithm to set of filtered data. The filter I was asked to implement was a second order high pass IIR filter. I get the array of filtered data and then I pass to my FFT function. Everytime I do, I am just getting all max peaks at 1 .
I use it like this :
double[] fft = getFFT(iirFiltered);
return fft;
And this is how my getFFT() function looks like
private double[] getFFT(double[] m1){
double sum = 0;
for (int i = 0; i < m1.length; i++) {
sum += m1[i];
}
double mean = sum / m1.length;
for (int i = 0; i < m1.length; i++) {
m1[i] = m1[i] - mean;
}
int neft = 0;
int count = 0;
while (neft <= m1.length) {
neft = (int) Math.pow(2, count);
count++;
}
DSPLib.nFft(neft, m1);
double[][] filtered = DSPLib.getFFT();
double[] returnFiltered = new double[filtered.length];
for(int i=1;i< returnFiltered.length;i++){
//returnFiltered[i]= filtered[i][0]; // old one
returnFiltered[i]= Math.sqrt(filtered[i][0]* filtered[i][0] + filtered[i][1]*filtered[i][1]); //new one
}
return returnFiltered;
}
This is how I perform analysis :
private double[] performAnalysis (double[] rrIntervals) {
ArrayList<Double> splineRRIntervals = SlplineInterpolator.interpolate(rrIntervals);
ArrayList<Double> downSampledData = new ArrayList<>();
for (float i = 0; i < splineRRIntervals.size(); i = i + 1000f / (float) sampleRate) {
downSampledData.add(splineRRIntervals.get((int) i));
}
FileIO fileIO = new FileIO();
//fileIO.writeDoubleArrayToFile("interpolation_down.txt", convertDoubles(downSampledData));
double[] iirFiltered = new double[downSampledData.size()];
for(int i=0;i< iirFiltered.length ;i++){
if(i==0){
iirFiltered[i] = IIR.iirHpf1ecg(downSampledData.get(i),0,0);
}
else if(i==1){
iirFiltered[i] = IIR.iirHpf1ecg(downSampledData.get(i),downSampledData.get(i-1),0);
}
else{
iirFiltered[i] = IIR.iirHpf1ecg(downSampledData.get(i),downSampledData.get(i-1),downSampledData.get(i-2));
}
}
/*double[] iirFiltered = new double[splineRRIntervals.size()];
for(int i=0;i< iirFiltered.length ;i++){
if(i==0){
iirFiltered[i] = IIR.iirHpf1ecg(splineRRIntervals.get(i),0,0);
}
else if(i==1){
iirFiltered[i] = IIR.iirHpf1ecg(splineRRIntervals.get(i),splineRRIntervals.get(i-1),0);
}
else{
iirFiltered[i] = IIR.iirHpf1ecg(splineRRIntervals.get(i),splineRRIntervals.get(i-1),splineRRIntervals.get(i-2));
}
}*/
//added for IIR filter
iirFilteredForPlot = new double[iirFiltered.length];
for (int i = 0; i < iirFiltered.length; i++){
iirFilteredForPlot[i] = iirFiltered[i];
}
//end for graph
double[] fft = getFFT(iirFiltered);
// logLFHF(); // added this new
return fft;
}
My output gives me a weird FFT graph and no matter whatever frequency I am on, maxPeak always comes at 1
Please guide me as I am new to signal processing.
PS : At a sampling rate of 4d, and heart rate of 240 bpm,I get 224 RR Interval values and 256 values for FFT output (this code somehow gives all real values only) , Max Magnitude: 19202.405718996466 , HF:: 5.35238130772106E7 , LF:: 6.235056793402985E7