I am trying to make a surrogate time series of a discrete data series using python, basically I wish to keep the amplitude same and change the frequency
I take a Fourier Transform of the data I separate the angles and the amplitudes of each fourier coefficient I keep the amplitudes intact while randomizing the phase angles I multiply the amplitudes with the new phases then take an inverse Fourier Transform However, when I plot the inverse transform, it does not match the values of the original data series Following is my python script:
import numpy as np
import matplotlib.pyplot as plt
x=np.linspace(1,12,12)
y=np.array([23,40,3,100,161,667,845,231,978,102,79,27])
#Get Fourier coefficients into amplitude and phases
ft=fft.rfft(y)
amp=np.abs(ft)
phi_old=np.angle(ft)
tlast=phi_old[-1]
#-Randomize phase keeping amplitude unchanged
phi_new=np.random.uniform(0,1.,size=phi_old.shape)+phi_old
phi_new[-1] = tlast # restore Nyquist bin original phase
nft=amp*np.cos(phi_new)+(1j*amp1*np.sin(phi_new))
#Take ifft
y2=fft.irfft(nft)
#Plot 'em
f=plt.figure(figsize=(7,7))
ax1=f.add_subplot(211)
ax1.plot(x,y)
ax1.grid()
plt.title("x vs y")
ax2=f.add_subplot(212)
ax2.grid()
ax2.plot(x,y2)
plt.title("Inverse Fourier Transform of y")
plt.tight_layout()
plt.show()
This script however seems to work well with y=sin(x) I have tried using fft and ifft instead of rfft and irfft but the values do not match with the original data. Again, I just wish to change the shift the plot, or change it's frequency, without altering the y-values, like if we change the phase of a sine wave it gets shifted, but its amplitude does not change, I am trying to achieve exactly that for my discrete data. What am I doing wrong? Please help.(see plot)