Skip to main content
35 events
when toggle format what by license comment
Mar 7, 2022 at 13:20 history edited teeeeee CC BY-SA 4.0
edited body
Sep 25, 2020 at 11:47 history edited teeeeee CC BY-SA 4.0
added 50 characters in body
Sep 25, 2020 at 11:42 history edited teeeeee CC BY-SA 4.0
added 50 characters in body
Apr 16, 2020 at 12:00 history edited teeeeee CC BY-SA 4.0
added 192 characters in body
Apr 15, 2020 at 16:49 history edited teeeeee CC BY-SA 4.0
added 21 characters in body
Apr 15, 2020 at 12:10 history edited teeeeee CC BY-SA 4.0
added 13 characters in body
Apr 15, 2020 at 10:53 comment added Jonas Jo true, I was thinking of visualizing the amplitude. This would only be correct if I'd focus on the positive frequencies only.
Apr 15, 2020 at 10:14 comment added teeeeee Your PSD is now all good, but I think your magnitude is still not quite right. You need to remove the factor of 2.
Apr 15, 2020 at 10:06 history edited teeeeee CC BY-SA 4.0
added 369 characters in body
Apr 15, 2020 at 9:57 comment added Jonas Jo those were the missing puzzle pieces for me, I adapted my post with a threshold for the phase and the calculation of the PSD. Thanks for the ongoing support.
Apr 15, 2020 at 9:45 comment added teeeeee As far as your PSD values, I think you missed a factor of $dt$. In this answer dsp.stackexchange.com/a/32206/38419 you can see that the discrete version of the PSD can be written as $$\frac{1}{N\cdot dt}|\textrm{yfft}\cdot dt|^2$$ where $\textrm{yfft}$ is the raw output from the fft(). Instead, you are plotting $$\frac{|\textrm{yfft}|^2}{N}$$. Add the extra $dt$. Does that fix it?
Apr 15, 2020 at 9:37 comment added teeeeee To fix the funny business with the phase, try adding some thresholding on the output of the fft, like so yfft = [0 if abs(yfft_) < 1.0e-10 else yfft_ for yfft_ in yfft]. Add this line directly after you do the fft. This is because the phase angle is calculated using arctan of the real divided by the imaginary component, so if you have numerical noise (inherent in the computer precision) then the division blows up.
Apr 15, 2020 at 9:30 comment added Jonas Jo Thanks for these suggestions on adjustments. Now it works quite well already. Two open points that I see at the moment: 1. The phase value of 2.712 for +3Hz is correct, but why is the Phase signal so distorted in comparison to yours? Is that because of the inaccuracy of Pythons FFT method ? 2. My PSD magnitudes are 10 times too big.
Apr 15, 2020 at 9:15 history edited teeeeee CC BY-SA 4.0
added 13 characters in body
Apr 15, 2020 at 9:10 vote accept Jonas Jo
Apr 15, 2020 at 9:09 history edited teeeeee CC BY-SA 4.0
added 14 characters in body
Apr 15, 2020 at 8:46 history edited teeeeee CC BY-SA 4.0
added 32 characters in body
Apr 15, 2020 at 8:42 comment added teeeeee That should correct all the frequency axis problems. To see the phase, try plotting np.angle(yfft), and you should see a value of 2.712 for the phase of the +3Hz frequency.
Apr 15, 2020 at 8:35 comment added teeeeee @JonasJo it also looks like you made a mistake in how you define fs. Change fs = tmax / npts to dt = tmax / npts, and then add fs = 1/dt. Finally, I would change the time vector definition to this t = np.linspace(0, tmax-dt, npts) so that you coherently sample the wave, as I mentioned in my answer. Finally, change your frequency definition to this: freq = np.fft.fftfreq(N)*fs
Apr 15, 2020 at 8:26 comment added teeeeee @JonasJo you need to apply fftshift() around the output of your fft, to make it match with your frequency vector: yfft = np.fft.fftshift(np.fft.fft(y))
Apr 15, 2020 at 8:19 comment added Jonas Jo Hello teeeeee, thanks for your answer. The first link was very helpful. I didn't know that the PSD is the physically correct representation. I'll try to use it in the future. I can understand your answer, but I'm still wondering why my solution, does not show the magnitudes at frequency 3 with Phase 2.7. Is my way of calculating the phase correct?
Apr 15, 2020 at 8:09 history edited teeeeee CC BY-SA 4.0
added 608 characters in body
Apr 15, 2020 at 7:37 history edited teeeeee CC BY-SA 4.0
added 87 characters in body
Apr 15, 2020 at 7:27 history edited teeeeee CC BY-SA 4.0
added 2 characters in body
Apr 14, 2020 at 23:38 history edited teeeeee CC BY-SA 4.0
added 85 characters in body
Apr 14, 2020 at 23:19 history edited teeeeee CC BY-SA 4.0
added 49 characters in body
Apr 14, 2020 at 23:12 history edited teeeeee CC BY-SA 4.0
added 80 characters in body
Apr 14, 2020 at 22:35 history edited teeeeee CC BY-SA 4.0
added 385 characters in body
Apr 14, 2020 at 22:30 history edited teeeeee CC BY-SA 4.0
added 385 characters in body
Apr 14, 2020 at 22:25 history edited teeeeee CC BY-SA 4.0
added 385 characters in body
Apr 14, 2020 at 22:08 history edited teeeeee CC BY-SA 4.0
added 177 characters in body
Apr 14, 2020 at 22:01 history edited teeeeee CC BY-SA 4.0
added 177 characters in body
Apr 14, 2020 at 21:55 history edited teeeeee CC BY-SA 4.0
added 177 characters in body
Apr 14, 2020 at 21:49 history edited teeeeee CC BY-SA 4.0
added 177 characters in body
Apr 14, 2020 at 21:40 history answered teeeeee CC BY-SA 4.0