I have been attempting to make a basic, slow, DFT in Matlab and have noticed peculiar behavior that I don't understand.
I have been trying to plot the phase of a 100Hz sinewave captured at 250kHz sample rate with a record length of 10k points. I find that the real part of the DFT is negative at 100 Hz, which I think makes sense due to a sinewave having negative correlation with a cosine wave. However, the imaginary part at 100Hz is also negative, which again makes sense because a sinewave is shifted -90 degrees from a cosine wave.
When I take the inverse tangent of the real/imaginary, obviously this is a positive number. Resulting in a +90 phase shift instead of a -90. Am I misunderstanding something, or do I just have incorrect results?
edit: I've realized the issue is that due to spectral leakage and the fact that this operation there are non-zero magnitudes that need to be filtered out before calculating the phase.
Is there a good way to choose a threshold for when to zero out DFT results? It seems a hard value to choose as if I throw in an arbitrary waveform then I have no information beforehand to choose a proper threshold value. My initial idea is to calculate the bin size based on the time length of the input, and then use a lookup table to change the threshold to be 10%, 1%, 0.1%, etc, of the maximum magnitude in the DFT.
atan2
. $\endgroup$ – MBaz Jan 23 '19 at 18:13