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

[Matlab] FFT Gaussian x-space -> p-space scalings.

  1. Jul 24, 2010 #1
    Hi There,
    Im having a little trouble with scalings required for a fft performed in Matlab. So here is the story:
    I construct a position space gaussian, plot this guy out to 6 stdDev. My frontfactor is such that my probability density is normalized.
    I know what the actual fourier transform should be in momentum space, thus when I use fft in matlab I should get something that lies ontop of this solution.

    My problem is that I can't, also I cannot really see where things are going wrong. So here is some code to peruse if you're curious about helping,
    Thanks in advance :D


    %A gaussian wavepacket
    asimParam %physical constants [SI units]

    %experimental parameters
    k0=0; %planewave with this wavenumber is modulated by a Gaussian
    w=100e-6; %Gaussian width parameter

    %simulation parameters
    stdDevNum=6; %number of standard deviations before truncation
    disp(['Proportion of total Gaussian within (' num2str(stdDevNum) ') std dev. :'...
    num2str(erf(stdDevNum/sqrt(2)))]);

    %calculate the maximum momentum to use before truncating the Gaussian, this
    %is done in terms of the maximum number of std. dev. to consider. This can
    %be done because an explicit form of the std dev. is known (See Sakurai)
    stdDevX=w/sqrt(2);
    xMax=stdDevNum*stdDevX;
    grX=1024; %make sure this is base 2pwr as this optimises fft

    x=linspace(-xMax,xMax,grX)';
    dx=x(2,1)-x(1,1);

    %calculate the x-space wavefunction |psi(x,t=0)>
    xPsi=1/(pi^(1/4)*sqrt(w))*exp(i*k0*x-x.^2/(2*w^2));

    rhoPsiX=conj(xPsi).*xPsi; %rho as a func of x
    rhoPsiXint=sum(dx*rhoPsiX); %sum of density (step size uniform);


    %Momentum space wavefunction: |phi(p,t=0)>
    %First use the explicit form given in Sakurai, then compare the fft
    %function in Matlab to ensure things are working correctly.
    pPhiAn=@(pIn)sqrt(w/(hb*sqrt(pi)))*exp(-(pIn-hb*k0).^2*w.^2/(2*hb^2));
    stdDevP=hb/(sqrt(2)*w);
    N=grX; %same number of points as for x-space
    dk=1/(N*dx); %such that fourier transform has correct units
    dp=hb*dk; %now rescale to momentum

    %pMax=stdDevP*stdDevNum;
    pMax=dp*N/2;
    pIn=linspace(-(pMax+hb*k0), (pMax+hb*k0), N)';
    pPhiS=pPhiAn(pIn);
    rhoPhiPs=conj(pPhiS).*pPhiS;
    rhoPhiPsInt=sum(dp*rhoPhiPs); %sum of density (step size uniform);

    %Now using Matlab's fft
    pPhi=fftshift(fft(xPsi));
    rhoPhiP=conj(pPhi).*pPhi;

    %test if it works back to x-space
    xPsiF=ifft(fft(xPsi));
    rhoPsiXF=conj(xPsiF).*xPsiF;

    %The rest of this m-file is comprised of plotting
     
  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