Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Randomize phase shift in Fourier Transform

  1. Jan 29, 2012 #1
    I have some questions regarding shifting the phase of a fourier transformed spectrum :

    I have a spectrum with flux on the Y-axis and wavelength on the X-axis. What I want to do is take the Fourier transform of this spectrum. Then add a random phase between 0 and 2pi to the phase only. Then take the inverse Fourier Transform of this. The piece of code I wrote in IDL for a simple example is below. I was hoping to scramble up the spectrum by doing this. But I am not sure if I have achieved that goal. I have two questions

    1. The final spectrum ( for some random phases) are vertically offset from the original spectrum. If the DC component is zero in the original spectrum, then this problem doesnt exist! Why is that so?

    2. The amplitude of the final signal varies a lot from the original spectrum. I wasnt expecting that either. why is that?

    3. All I want is that the components of the original spectrum be jumbled up in the X-direction (ie the wavelength direction). How can it be done?

    MY CODE :

    n = 256
    x = FINDGEN(n)
    y = COS(x*!PI/6)*EXP(-((x - n/2)/30)^2/2)+1.00


    yfft = fft(y)

    magnitude = abs(yfft)
    angle = ph(yfft)

    for count=0, 300 do begin

    rand = randomu(seed, 1)*2*!pi
    randph = replicate(rand, 256)

    fft_signal = magnitude*exp(complex(0,1)*(angle+randph))
    ifft_signal = (fft(fft_signal, /inverse))

    wait, 0.2

    plot, x, y
    oplot, x, (ifft_signal), color=2


  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted