'Generating IFFT curve manually to use it for the forecasts

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.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source