FFT in dB scale

조회 수: 89 (최근 30일)
Alexander Voznesensky
Alexander Voznesensky 2017년 1월 23일
댓글: Alexander Voznesensky 2017년 2월 22일
Hi everybody! I'm trying to use dB scale in FFT. I've found the example http://www.dsplib.ru/content/winex/winex.html
I'm trying to get the same results in MATLAB. But I can't. I have different amplitude levels. What's wrong? So, I do:
Fs=1000;
T=1/Fs;
N=1024;
t=(0:N-1)*T;
f=(0:Fs/(N-1):Fs);
A0=1;
A1=0.003;
A2=10e-4;
f0=220;
f1=240;
f2=230;
s=A0*cos(2*pi*f0*t)+A1*cos(2*pi*f1*t)+A2*cos(2*pi*f2*t);
plot(f,mag2db(abs(fft(s))));

채택된 답변

David Goodmanson
David Goodmanson 2017년 1월 24일
hi Alexander I assume you are looking for a couple of peaks at -6 dB. Otherwise this answer will not be of help. But to get -6 dB you need to divide the fft result by N before taking mag2dB. Before getting into that, I believe your frequency grid with the factor of N-1 is not quite right. It should have a factor of N and should not end at Fs:
f = (0:N-1)*Fs/N;
That change only scales the frequency axis though, and puts the peaks in the right spot. It does not affect the peak value. You will still not get -6 dB (right now it's more like -7) because f0 = 220 does not represent an exact periodic frequency to the fft. To get a sharp peak at -6 dB, the frequency must be a multiple of Fs/N = 1000/1024. You could replace 220 by 225*1000/1024 which is pretty close, but I think the best way is to just use N = 1000. The fft is blazingly fast anyway, so unless you are in some production situation doing a ten million of these, N = 2^n is not really necessary.
  댓글 수: 7
David Goodmanson
David Goodmanson 2017년 2월 7일
For the fft to produce a sharp spike, there must be an exact integral number of oscillations in the time domain function. Otherwise what is repeating is not (say) a cosine wave but rather a cosine wave whose last oscillation is truncated. So (in your notation) f*t must equal an integer m. But for an N-point fft, t = NT and Fs = 1/T, so f = m Fs/N. and f must be a multiple of Fs/N. That's not the case for Fs = 1000, N = 1024, f = 220 but it is when you change N to 1000.
Also, you have A2 = 10e-4 not 1e-4, so -60 dB.
Alexander Voznesensky
Alexander Voznesensky 2017년 2월 22일
"Also, you have A2 = 10e-4 not 1e-4, so -60 dB."
Yes, it's my mistake. Now it's all right! Thank you very much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by