I need to know relative phases of two signals (identical slowly changing frequency). BUT also i want to do smoothing of this phase difference over time.
At the moment i do complex FFT of complex input (two channels), rearrange output and get 2 real spectrums separately for each signal, calculate phases, calculate phase differences, calculate amplitudes. After that i use phase to project amplitude on X and Y plane to do time-smoothing, bacause averaging phase not taking into account amplitude gives bad result. Then, after smoothing, i take smoothed X and Y and calculate atan2 and get smoothed phase difference. So it works this way.
Why i still have this question i because while observing complex FFT output i realized, that it somehow can be directly smoothed, and with trial and error i was able to produce algorithm, that analyses scalar multiplication of complex spectrum vectors. But it works only for signals with similar amplitude:
View attachment 92327
Actually it takes complex spectrum, calculate amplitudes using sqrt for full 1024 spectrum (real 512 and "negative" frequency part from 512 to 1024).
Then i add sign to amplitude spectrum using this way:
This thing can be smoothed, because specL and specR is just an vector (X,Y). Again, i realized how to do that only for signals for similar amplitude.
So i now use the old way:
1) take real spectrums of each signal
2) calculate phases
3) calculate amplitudes
4) calculate phase differences
5) project amplitudes using phase on X,Y axis
6) smooth
7) atan of smoothed X,Y to get smoothed amplitude and phase
Another method (code above), that worked only for similar amplitude, is much more effective:
1) calculate complex spectrum
2) calculate amplitudes
3) change sign of amplitudes based on complex spectrum
4) smooth
5) make atan of smoothed data to get smoothed phase and amplitude
it would be faster and less of code.