我想通过反向快速傅立叶变换找到时间置换曲线
import numpy as np
import matplotlib.pyplot as plt
N=1000; T=10; dt=T/N
t=np.arange(0,N*dt,dt)
#system properties
wn = 4 * np.pi
w=0.2*wn
Tn = 2*np.pi/wn
fn = 1/Tn
m = 1
Z = 0.05
k = wn*wn * m
c = 2*m*wn*Z
######################################################
P = np.sin(wn * t)
#Frequency response
L = len(P)
a = np.arange(L)
freq = a * (1/dt) / L
freq = freq[range(int(L/2))]
Pf = np.fft.fft(P)/L
Pf = Pf[range(int(L/2))]
FFT = 2*abs(Pf)
#########################################################
# transfer function
H=(1/k)*(1/(1+(w/wn)**2)+1j*(2*Z*(w/wn)))
Uf=2*Pf*H
# for i in range(0,int(N/2)):
# Uf[N-i-1] = np.conjugate(Uf[i+1])
ut= np.real(np.fft.ifft(Uf)*(1/dt))
plt.plot(t, ut)
plt.show()
我不知道这个 ValueError ValueError:x 和 y 必须具有相同的第一维度,但具有形状 (1000,) 和 (500,) 我想通过快速傅里叶逆变换找到时间-位移曲线
import numpy as np
import matplotlib.pyplot as plt
N=1000; T=10; dt=T/N
t=np.arange(0,N*dt,dt)
#system properties
wn = 4 * np.pi
w=0.2*wn
Tn = 2*np.pi/wn
fn = 1/Tn
m = 1
Z = 0.05
k = wn*wn * m
c = 2*m*wn*Z
######################################################
P = np.sin(wn * t)
#Frequency response
L = len(P)
a = np.arange(L)
freq = a * (1/dt) / L
freq = freq[range(int(L/2))]
Pf = np.fft.fft(P)/L
Pf = Pf[range(int(L/2))]
FFT = 2*abs(Pf)
#########################################################
# transfer function
H=(1/k)*(1/(1+(w/wn)**2)+1j*(2*Z*(w/wn)))
Uf=2*Pf*H
# for i in range(0,int(N/2)):
# Uf[N-i-1] = np.conjugate(Uf[i+1])
ut= np.real(np.fft.ifft(Uf)*(1/dt))
plt.plot(t, ut)
plt.show()
i don't know this ValueError
ValueError: x and y must have same first dimension, but have shapes (1000,) and (500,)
I want to find the time-displacement curve through inverse fast Fourier transform
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
plt.plot()
功能只是抱怨t
和ut
没有相同的长度。此行
pf = pf [range(int(l/2))]
将pf
从长度n
到n /2
。这会影响uf
,因此ut
,这就是为什么您会收到错误消息的原因。我不确定您在此命令中要做什么...您是否试图过滤某些频率?无论哪种方式,再看一下此命令都可能给您想要的东西。The
plt.plot()
function is just complaining thatt
andut
do not have the same length.This line
Pf = Pf[range(int(L/2))]
takesPf
from an array of lengthN
toN/2
. This affectsUf
and consequentlyut
, and that is why you get the error message. Im not sure what you are trying to do in this command... are you trying to filter out certain frequencies? Either way, taking another look at this command might give you what you want.