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

Homework Help: How i will write the code for fft

  1. Feb 6, 2009 #1
    1. The problem statement, all variables and given/known data


    How i will write the code for fft
    2. Relevant equations

    ACos(ωt+φ)

    3. The attempt at a solution
    n = 100;
    n = 0:n;
    nodd = 2*n + 1;
    T=n*pi/2w
    w=2*pi*1.93*10^14;
    phi= 0;
    A=-6:6;
    X= A*cos(w*T+pi)
    %Here it generates error
    " ??? Error using ==> mtimes Inner matrix dimensions must agree."
    Y=fft(X)
    Plot(A,T)


    When ever i use two variable values it gives me the same error, how can i fix that.
    Regards
     
  2. jcsd
  3. Feb 9, 2009 #2
    Re: Fft

    I think the error lies in that MATLAB treats * as matrix multiplication. In
    > X = A*cos(w*T+pi)
    the cos part is a 1x101 matrix (1 row, 101 columns) while the A part is a 1x13 matrix (1 row, 13 columns). Clearly, those can't multiply. You should probably just use a scalar for A. Then if you want to know the Fourier transforms of different magnitudes, just do a for loop but make sure the fft is within the for loop.
     
  4. Feb 9, 2009 #3
    Re: Fft

    Dear Spring
    many thanks for your reply. Well i have solve that problem. Now am taking the FFT how i will add Limit to FFT i.e [0,T]
    .
    %E= Acos(wt+pi) [0,T]" Time domain-> Frequency domain
    n=100;
    n=0:n;
    nodd=2*n+1;
    %pi=0; %"0:360
    w=2*pi*1.93*10^14;

    T=n*pi/2*w;
    A=-50:50;% size(A)=[ 1 101] " to adjust matrix mismatch
    X=A.*cos(w*T+pi);% element wise mulitpication [size(X)=[1,101]
    Y=real(fft(X))
    plot(T,Y)


    Regards
    Shahzad
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook