help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Any FFT expert around?


From: Brian Kaczynski
Subject: Re: Any FFT expert around?
Date: Wed, 12 Feb 2014 17:24:00 +0100

Hi Oxy,

Since you're taking the FFT of a complex vector it will have unique terms for negative vs. positive frequency.  You are correct that it makes more sense to think of the FFT from -Fs/2 to +Fs/2.  It's just that the Octave fft function doesn't compute the bins in that order.  Due to aliasing, any frequency Fs/2 + df is equivalent to (-Fs/2 + df) so it's more a matter of choice how you want to display the data.

If you prefer plotting from -Fs/2 to +Fs/2 I would change these two lines of your code as follows:

freq=linspace(-Fs/2,Fs/2-Fs/(Fs*at),Fs*at)'
freqsig=fftshift(fft(tdsig);

Let us know if that gives you what you want!

-Brian


2014-02-12 17:15 GMT+01:00 oxy <address@hidden>:
Hi Brian,

> The frequency vector for FFT should go from DC as bin 1 to slightly less
> than Fs in the last bin (Fs - Fs/N where N is the number of FFT points).

If i understand u correctly, the frequency vector (freq) must be written
as in this modified version of code below. However, according to Nyquist we
cannot measure a frequency higher than Fs/2. Thus i do not see
the meaning of plotting up to ~Fs.

Also, if I rerun the code below changing FsFactor, I again see this
dependency of the signal frequency on FsFactor.
I cannot understand it. Looks like basics, yet not that obvious.

  #---------- start code ------------
  clear all
  nu=10;                    % signal frequency
  at=5;                       % acquisition time
  T1=2                       % signal decay constant in time domain
  FsFactor=16;             % the ratio (sampling rate)/(signal
frequency), or Fs/nu

  clf
  Fs = FsFactor*nu;                             % Sampling rate
  t = ((0:(at*Fs-1))/Fs)';                         % Time vector
  % freq=linspace(-1,1,Fs*at)' * Fs/2;         % frequency vector, first version
  freq=linspace(0,1,Fs*at)' * Fs- Fs/(Fs*at);  % frequency vector
suggested by Brian
  tdsig=exp(-i*2*pi*nu*t).*exp(-t./(T1));    % time domain signal
  freqsig=fft(tdsig);                                % freq. domain signal
  subplot(1,2,1)
  plot(t,tdsig)
  axis([ 0 0.4])       % zooming time domain to see that period=1/nu
  subplot(1,2,2)
  plot(freq, freqsig)
  #---------- end code ------------

thx guys ...


> 2014-02-12 14:22 GMT+01:00 oxy <address@hidden>:
>
>> hey guys,
>>
>> the (simple) code bellow is how i ve learned to do FFT according to
>> several docs online. However i observe a dependency of the signal
>> frequency in the spectrum on the constant FsFactor. In other words,
>> the signal frequency depends on the sampling rate. I should'nt be,
>> right? So what is wrong here?
>>
>>   #---------- start code ------------
>>   clear all
>>   nu=10;                    % signal frequency
>>   at=5;                       % acquisition time
>>   T1=2                       % signal decay constant in time domain
>>   FsFactor=8;             % the ratio (sampling rate)/(signal
>> frequency), or Fs/nu
>>
>>   clf
>>   Fs = FsFactor*nu;                             % Sampling rate
>>   t = ((0:(at*Fs-1))/Fs)';                         % Time vector
>>   freq=linspace(-1,1,Fs*at)' * Fs/2;         % frequency vector
>>   tdsig=exp(-i*2*pi*nu*t).*exp(-t./(T1));    % time domain signal
>>   freqsig=fft(tdsig);                                % freq. domain
>> signal
>>   subplot(1,2,1)
>>   plot(t,tdsig)
>>   axis([ 0 0.4])       % zooming time domain to see that period=1/nu
>>   subplot(1,2,2)
>>   plot(freq, freqsig)
>>   #---------- end code ------------
>>
>> Do it yourself. Just rerun the code trying different values of
>> FsFactor (eg: 2, 4, 8).
>> Thx a lot for any hint!!!
>>
>> oxy
>>
>> ps: cross post
>> http://www.mathworks.com/matlabcentral/answers/115700-fft-why-signal-frequency-depends-on-sampling-rate
>> _______________________________________________
>> Help-octave mailing list
>> address@hidden
>> https://mailman.cae.wisc.edu/listinfo/help-octave
>>
>
_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave


reply via email to

[Prev in Thread] Current Thread [Next in Thread]