# How to smooth (or interpolate) phase of FFT and reduce data points

I am writing some code for audio analysis, and have currently got two signals with FFT performed on them.
I get the phase of my complex array by using:

ang = Math.atan(complex.im/complex.re)*180.0/Math.PI;


I then 'format' for wrapped phase:

if(complex.re < 0.0 && complex.im == 0.0){ang = 180.0;}
else if(complex.re < 0.0 && complex.im == -0.0){
ang = -180.0;}
else if(complex.re < 0.0 && complex.im > 0.0){
ang += 180.0;}
else if(complex.re < 0.0 && complex.im < 0.0){
ang += -180.0;}
}


As I have converted this to degrees already, I then subtract channel 1 phase from channel 2 phase to give me the phase difference:

double phaseDiff = (((double)chan1phase.get(i)) - ((double)chan2phase.get(i)));


Finally, I add a method for keeping wrapped phase whilst subtracting the two phases:

if (phaseDiff < -180){
phaseDiff += 360;
}
if (phaseDiff > 180){
phaseDiff -= 360;
}


This works really well currently, however there are too many data points for my application to respond quickly. I am working with 16k or 32k FFT size, and that's a lot of data to plot and redraw quickly when I manipulate my data. I also occasionally get one or two data points throughout the whole plot which are noisy or differ from the expected path of travel, which I would like to get rid off.

I have already used a smoothing function to display my magnitude vs frequency, and this responds really quickly. However I am not confused on how best to smooth phase. I need to reduce the data points to approximately 1000 points over the audible frequency range (20Hz - 20kHz).

However I cannot just use the same method as I used for magnitude because of the wrapped phase. Would I need to average the data points within an octave (or preset band) prior to wrapping the phase?

Or am I better disregarding some points and interpolating the data?

Any guidance would be appreciated. Apologies if there is too much actual code here, I realise this is a DSP site and not programming site, but thought it useful to see exactly what I am doing (or where I have gone wrong!).

• You can save some computation time by using "Math.atan2" and also by sticking with radians and not converting to degrees. Good answers to the rest of your questions really requires knowing what your are trying to accomplish. – Cedron Dawg Feb 25 '18 at 15:33
• I have trouble following you. What is your problem exactly? Is it the refresh rate or the the noisy data? Does smoothing your phase plot the only problem you are trying to solve? If you can't filter a phase/frequency plot because the phase wrap, why not unwrap it? You say that you cannot smooth like the magnitude, but you haven't told us how you do. If you are trying to remove few noisy points, maybe a median filter would be a good fit; that should behave good with wraping phase. – Pier-Yves Lessard Dec 17 '18 at 4:35