help-octave
[Top][All Lists]
Advanced

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

FFT spectrum analyzer question


From: Bolin Hsu
Subject: FFT spectrum analyzer question
Date: Tue, 13 May 2014 17:09:59 -0700

I saw the thread about FFT spectrum analyzer at http://octave.1599824.n4.nabble.com/FFT-Spectrum-Analyzer-td4630647.html, and gave it a try. From http://en.wikipedia.org/wiki/Bartlett%27s_method, I got the idea that the energy is abs(fft(x))^2/M. So I ended up with the program below. The signal was sine wave with peak amplitude 1, so I thought I would get the RMS amplitude 1/sqrt(2). But the result I got was much smaller. And the result varies with different FFT size. What am I missing in this program?

Fs=44100;
w=14000;
t=0:1/Fs:1;
x=sin(2*pi*w*t);
len=length(x);
for N = [128 256 512 1024 2048 4096 len]
  for i = [1:N:len]
    if (i+N-1 <= len)
      xdft=fft(x(i:i+N-1));
      xdft=xdft(1:N/2+1);
      psdx=(1/(Fs*N)).*abs(xdft).^2;
      psdx(2:end-1)=2*psdx(2:end-1);
      freq=0:Fs/N:Fs/2;
      printf('[%5d, %5d] %f\n', N, i, max(psdx))
    endif
  endfor
endfor


Thanks,
Bolin

reply via email to

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