# How to achieve a smoothed frequency phase response with no outliers

I have two sampled signals, which I then perform wavelet analysis on, by synthesising the Filterbank, perform the dft on each kernel, and the dft on the sampled signals, and multiply together.

Using this I can get successfully extract the magnitude of the signal, and either take an average or identify the time response of a frequency.

Now I would like to extract the phase. Taking either an instance in time, or averaging the mean signal I can get the phase and plot it, using atan2(im / re) for each signal, and then subtracting one from the other. However it appears to be very noisy. Although I can identify the phase trend, there are a lot of sporadic results that lie far out of the trend.

Researching into this a little, I have found there can be issues with rounding small floats, and it is good to set a threshold for the phase, so everything below the threshold is rounded to 0. This returns similar results.

What I am witnessing looks like some kind of phase noise, reading this it is my understanding this occurs when the frequency is not an exact integer number of cycles for the dft size. This is where I start to get confused as I have my Filterbank frequencies and I have the dft size. How do these two relate? Would I need to remove all results where the centre frequency of each filter does not meet an integer number of cycles for the sample length?

Am I on the right path here, or is there something else that would be causing my phase noise. Failing this, is there any decent way to filter out outliers in a signal.

If I go about not performing Wavelet analysis, and do a straight forward dft on an incoming signal and extract the phase, I get similar results, so I think phase noise is along the right path, please point me in the right direction!

If your signals are not perfectly integer periodic in the FFT aperture (width), the phase measurements of those narrow band signals will toggle between FFT result bins. This phase toggling will look like phase noise, but is actually a windowing artifact. It is due to any window edge discontinuity from any non-exactly-integer-in-aperture periodicity in the signal (plus the fact that all the basis vectors of a DFT are perfectly circular in aperture).

To stop this phase toggling (apparent phase noise), perform an FFTShift before the FFT. The fftshift will rotate the edge discontinuity away from sample 0, and reference the DFT phase estimate to the center of your data window, where it is likely continuous (instead of to a phase discontinuity between the last sample and first sample of the data).

There are (at least) 2 ways to perform a time-domain fftshift. The first is to circularly rotate the data vector 50% after windowing but before performing the FFT. The 2nd way is to complex conjugate every other result bin (odd ones usually) after the FFT. Due to the DFT shift property, these two methods produce identical results. Note that these are in the opposite order from doing a frequency domain fftshift.

• I am just researching this now, so I half understand this. I shall try implementing FFT shift and see where I get to. This would only need to be performed on the incoming sample data set, correct? Ie my filterbanks taper to zero at the edges anyway so presumably this is alright to use as is without shifting each filter. This sounds like the missing puzzle piece. Apr 17, 2019 at 16:49
• Following up on this I still require more help. I do not see how reordering the FFT bins to order: negative frequencies, DC, positive frequencies helps with moving the phase reference to the centre of the window (unless I am confused as to when this shift should take place!). The FFT has already been calculated, therefore I have a complex number for that bin, and regardless of where it is in the order, it remains the same vector. Am I doing the shift in the wrong place? To be clear I have a discrete signal, I want to find the phase for each FFT bin, without the discontinuities. Apr 18, 2019 at 7:03
• Is the DC component the reference for the phase? Continuing on this, I am using Apple's Accelerate framework, which results in just the DC and positive frequencies. Would I need to manually add in the negative frequencies before this result? This is where I do not understand how to deal with this Apr 18, 2019 at 7:08
• See update to answer. Apr 18, 2019 at 14:28