Python Forum
scipy fftfreq parameters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
scipy fftfreq parameters
#2
Yes, you are using the fftfreq function correctly. The first argument to fftfreq is the length of the input array (in your case, the length of v_t), and the second argument is the sampling interval between each time point (in your case, 1e-11).

Your code should produce a plot of the magnitude of the Fourier coefficients up to a frequency of 50000 (since you are taking only the first 50000 elements of xf and yf). Note that the frequency axis in this plot is in units of cycles per second (Hz), not in units of time. To convert the frequency axis to units of time, you can take the reciprocal of the frequency values. For example, if you want the frequency axis in units of GHz, you can divide the frequency values by 1e9. If you then take the reciprocal of the frequency axis, you will get the time axis in units of seconds.

Here's an example of how to plot the Fourier transform with a time axis:

from scipy.fft import fft, fftfreq, ifft
import numpy as np
import matplotlib.pyplot as plt

# Generate a pulse with duration 1 microsecond and 100000 time slots
dt = 1e-11  # Time interval between each time slot
t = np.arange(0, 1e-6, dt)  # Time array
v_t = np.sin(2*np.pi*1e6*t)  # Pulse signal

# Compute the Fourier transform
yf = fft(v_t)
xf = fftfreq(len(v_t), dt)

# Plot the magnitude of the Fourier coefficients with a time axis
freq = xf / 1e9  # Convert frequency axis to GHz
time = 1 / freq  # Convert frequency axis to time axis in seconds
plt.plot(time, np.abs(yf))
plt.xlabel('Time (s)')
plt.ylabel('Magnitude')
plt.show()
In this example, I've generated a sine wave pulse signal with a frequency of 1 MHz. You can replace v_t with your own pulse signal. The resulting plot should show the magnitude of the Fourier coefficients as a function of time.
Reply


Messages In This Thread
scipy fftfreq parameters - by quest - Apr-14-2023, 12:11 AM
RE: scipy fftfreq parameters - by farshid - Apr-20-2023, 04:19 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020