计算时域信号的频率

#!/usr/bin/python
from __future__ import division
from pandas import DataFrame
import numpy as np
import matplotlib.pyplot as plt

Fs = 10000 # sampling frequency: 1000 Hz
dt = 1/Fs # sampling period
N = 500 # samping points
T = N * dt # span

# time ana

t = np.linspace(0, T, N, endpoint = False) # time
x = np.loadtxt(‘ccc.txt’)
df_x = DataFrame({“t”: t, “x”:x}) # simplify visulization

ax = df_x.plot(x = ‘t’, y = ‘x’, xlim = (0, 0.055))
ax.set(xlabel = “t (second)”, ylabel = “x(t) ADC”) # change axis titles
plt.show()

# spectrum ana

f = np.linspace(0, Fs, N, endpoint = False)
tik = np.linspace( 0, 10000, 100, endpoint = False)
X = np.fft.fft(x) # Discrete Fourier Transform by fft
X = np.abs(X) # just for magnitude
df_f = DataFrame({“f”:f, “fft”: X})

ax = df_f.plot(x = ‘f’, y = ‘fft’, xlim = (0, Fs/2), ylim = (0, np.max(X)*1.1*0.01), xticks = tik )
ax.set(xlabel = “Freq(Hz)”, ylabel = “Mag”)
plt.show()

0 回复

发表评论

Want to join the discussion?
Feel free to contribute!

发表评论