我在使用 python 中的 scipy fft 模块获取简单正弦曲线的相位时遇到问题。我密切关注本教程并将 matlab 代码转换为 python。但是,无论我使用哪个阶段作为输入,图表始终显示 3。我缺少什么?
import numpy as np
import matplotlib.pyplot as plt
import scipy.fftpack
import cmath
A=10
fc = 10
phase=60
fs=32#Sampling frequency with oversampling factor of 32
t = np.arange(0,2,1/fs)
#Convert the phase shift to radians from degrees.
phi = phase*np.pi/180
x=A*np.cos(2*np.pi*fc*t+phi)
N=256
X = scipy.fftpack.fftshift(scipy.fftpack.fft(x,N))/N
df=fs/N #Frequency resolution.
sampleindex = np.arange(-N/2,N/2,1) #Ordered index for FFT plot.
f = sampleindex*df #x-axis index continued to ordered frequencies
raw_phases = np.angle(X)
X2=np.copy(X)#Store the …Run Code Online (Sandbox Code Playgroud)