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

Matlab normalization using fft

  1. Sep 22, 2011 #1
    Hi,

    Let's say I have an input signal

    [tex] f(t,0)= \sum_n A_n cos(w_nt) [/tex]

    And we know that

    [tex] f(t,x)= \sum_n A_n cos(k_nx-w_nt) [/tex]

    and we also have the relationship between k and w. We can find the coefficients A_n by taking a Fourier Transform of the relationship for f(0,t).

    Here's my question. How is the sum for f(t,x) normalized? If this is unclear, below is an example:

    I've been trying test cases to figure out what the relationship is by prescribing f(0,t) to be some easy function i.e.

    [tex] f(t,0)= cos(\omega_1t) + 2cos(\omega_2t) [/tex]

    Theoretically, we know that

    [tex] \bar{f}(t,x)= cos(k_1x-\omega_1t) + 2cos(k_2x -\omega_2t) [/tex]

    But if I did not know precisely what f(t,0) is and went through this numerically, I'd have

    [tex] f^*(t,x)= \sum_n A_n cos(k_nx-\omega_nt) [/tex]

    where

    [tex]A_n=\frac{1}{length(f(0,t))}fft(f(t,0)) [/tex]

    My problem is [tex] f^* \neq \bar{f} [/tex]. My question is, why is this the case? I think it comes down to normalizations but I'm not completely sure.

    Any help would be appreciated,

    Nick

    PS
    If you're interested, here's my code
    close all;
    g=10;
    A= [1 .5];
    tt=0:.5:2^5-.5;
    omega=[1 .25];
    kay=omega.^2/g;
    signal = zeros(length(tt),1);
    for i=1:length(tt);
    signal(i,1) = sum(A.*cos(tt(i)*omega));
    end
    Fs= 50;
    xx=1:.5:100;
    yy=signal;
    [YY,ff]=positiveFFT(yy,Fs); % this sets up our independent variable frequency as we want it
    kk=(2*pi*ff).^2/g;

    ETAETA=zeros(length(tt),length(xx));
    for i =1:length(tt)
    for j=1:length(xx)
    ETAETA(j,i)=real(sum(YY'.*cos(kk*xx(j)-2*pi*ff*tt(i))));
    end
    end
    figure (1)
    imagesc(xx,tt,real(ETAETA));
    set(gca,'YDir','normal');
    caxis([-0.01 0.01])
    colormap(copper);
    colorbar;
    xlabel('distance from wave maker'); ylabel('time');
    shading('interp')
    h = colorbar;
    set(get(h,'YLabel'), 'String', 'SSH');
    title('theoretical first order solution');
    % %
    % ETA3= zeros(length(xx),length(tt));
    % for i=1:length(tt)
    % for j=1:length(xx)
    % ETA3(j,i)= sum(A.*cos(kay*xx(j)-omega*tt(i)));
    % end
    % end

    % figure(2)
    % imagesc(xx,tt,real(ETA3)');
    % set(gca,'YDir','normal');
    % caxis([-0.01 0.01])
    % colormap(copper);
    % colorbar;
    % xlabel('distance from wave maker'); ylabel('time');
    % shading('interp')
    % h = colorbar;
    % set(get(h,'YLabel'), 'String', 'SSH');
    % title('theoretical first order solution');


    where
    positiveFFT.m is
    function [X,freq]=positiveFFT(x,Fs)
    N=length(x); %get the number of points
    k=0:N-1; %create a vector from 0 to N-1
    T=N/Fs; %get the frequency interval
    freq=k/T; %create the frequency range
    X=fft(x)/N; % normalize the data

    %only want the first half of the FFT, since it is redundant
    cutOff = ceil(N/2);

    %take only the first half of the spectrum
    X = X(1:cutOff);
    freq = freq(1:cutOff);
     
  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 Discussions: Matlab normalization using fft
  1. Fft in matlab (Replies: 0)

  2. Matlab (fft) (Replies: 1)

  3. FFT in Matlab (Replies: 12)

Loading...