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

IDL help with FFT.PRO

  1. Jan 29, 2012 #1
    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. Why is that so?

    2. The amplitude of the final signal varies a lot from the original spectrum for some phases. 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 = 257
    x = FINDGEN(n)
    y = COS(x*!PI/6)*EXP(-((x - n/2)/30)^2/2)+x/50.


    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
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

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

Similar Threads - help Date
Matlab MATLab: Not enough inputs for nlinfit Nov 16, 2017
Matlab Help needed to fix a matlab code Nov 8, 2017
LaTeX Help with page dimensions in latex Nov 2, 2017
Matlab Octave integral computation help Apr 20, 2017
Matlab 2D plotting error help please Aug 28, 2016