I have an array of length 4096 It contains the results of the calculated FFT. Results should be displayed on a window length of 1024 How to reduce the value from 4096 to 1024 and that the results remain correct.
Is this a good way?
int index = 0;
for(int i = 0; i < 1024; i++){
A = 0;
windowOffset = oldLength/1024; ---> 4096/1024 = 4
while(windowOffset > 0){
A += oldArray[index];
windowOffset --;
index++ -----> index will go to 4096
}
newArray[i] =A/(blockSize/1024); ---- summ of 4 values/4
}
Your approach of computing the average of four and displaying it is certainly valid. However, it is good for "smooth" data, and not so good for data that has a small number of high peaks.
Consider a situation when your FFT returned mostly small numbers, with 20 peaks exceeding the average roughly ten times. After applying your approach the peaks would remain, but they would exceed the average only 2.5 times. In other words, the histogram would become a lot smoother than it should have been.
One way to address this issue is to pick the max value of the four adjusted numbers. This would let you preserve peaks intact.