手动生成ifft曲线以将其用于预测

发布于 2025-01-24 00:30:18 字数 1520 浏览 0 评论 0原文

fft_tr = np.fft.fft(demand)
psd = (fft_tr * np.conj(fft_tr))/len(fft_tr)
ampl = (np.sqrt(fft_tr * np.conj(fft_tr))/(len(fft_tr)/2)).real
freq = 1/(1*len(train_df.demand)) * np.arange(len(train_df.demand))
l = np.arange(0, np.floor(len(freq)/2), dtype = "int")
df = pd.DataFrame(zip(freq,psd.real[l],fft_tr.real[l], fft_tr.imag[l],fft_tr[l],ampl[l]),columns = ["freq","PSD_r","fft_real","fft_imag","fft_tr","ampl"])
df["Theta"] = (df["fft_real"]/df["fft_imag"]).apply(lambda x : math.atan(x))


df1 = df.loc[df.PSD_r > 15000,["freq","Theta","ampl"]].reset_index().reset_index(drop = True, inplace=False)

def construct_Waves(time_series, v):
    
    ''' this function will construct the waves given a time series 
    along with the list of freq and phase which is theta'''

    return v[2] * np.sin(2*np.pi*time_series*v[0]-v[1])

v = np.zeros(len(time))
for i in range(1,len(df1)):
    x = list(df1.loc[i,["freq","Theta","ampl"]])
    x1 = np.array(construct_Waves(time+1,x))
    v = v+x1

plt.figure(figsize=(20,4))
plt.plot(v)

usp = sharing?手动ifft。从FFT结果。

这是我得到的图。实际的IFFT曲线就是这样。 “

可以帮助我手动获取实际曲线,以便我可以将其扩展到将来的时间段。

Data

fft_tr = np.fft.fft(demand)
psd = (fft_tr * np.conj(fft_tr))/len(fft_tr)
ampl = (np.sqrt(fft_tr * np.conj(fft_tr))/(len(fft_tr)/2)).real
freq = 1/(1*len(train_df.demand)) * np.arange(len(train_df.demand))
l = np.arange(0, np.floor(len(freq)/2), dtype = "int")
df = pd.DataFrame(zip(freq,psd.real[l],fft_tr.real[l], fft_tr.imag[l],fft_tr[l],ampl[l]),columns = ["freq","PSD_r","fft_real","fft_imag","fft_tr","ampl"])
df["Theta"] = (df["fft_real"]/df["fft_imag"]).apply(lambda x : math.atan(x))


df1 = df.loc[df.PSD_r > 15000,["freq","Theta","ampl"]].reset_index().reset_index(drop = True, inplace=False)

def construct_Waves(time_series, v):
    
    ''' this function will construct the waves given a time series 
    along with the list of freq and phase which is theta'''

    return v[2] * np.sin(2*np.pi*time_series*v[0]-v[1])

v = np.zeros(len(time))
for i in range(1,len(df1)):
    x = list(df1.loc[i,["freq","Theta","ampl"]])
    x1 = np.array(construct_Waves(time+1,x))
    v = v+x1

plt.figure(figsize=(20,4))
plt.plot(v)

i have written the above code in order to create the ifft manually. from fft result.

manual Ifft curve

this is the graph I am getting. Where the actual ifft curve is like this.
Numpy.fft.ifft curve

can some one help me in getting the actual curve manually such that i can extend it to future time periods.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文