简体   繁体   English

在Matlab中绘制FFT幅度频谱信号

[英]Plotting FFT Amplitude Spectrum signal in Matlab

I've trouble with plotting a correct FFT Amplitude Spectrum signal in decibels and Hertz. 我在以分贝和赫兹绘制正确的FFT振幅频谱信号时遇到麻烦。

Firstly, I just plot the FFT Spectrum signal in Hz and magnitude like this: 首先,我仅以Hz和幅度绘制FFT频谱信号,如下所示:

figure;
X_mags = abs(fft(signal));
bin_vals = [0 : N-1];
freq_ax_bins = bin_vals*fs/N;
N_2 = ceil(N/2);
plot(freq_ax_bins(1:N_2), X_mags(1:N_2));
title('FFT Spectrum signal 1');
xlabel('Frequency (Hz)')
ylabel('Magnitude');

This results in the expected plot with magnitude always > 0. Finally, I just want to do the same but in decibels: 这导致幅度总是大于0的预期图。最后,我只想做同样的事情,但以分贝为单位:

bin_vals = [0 : N-1];
freq_ax_Hz = bin_vals*fs/N;
N_2 = ceil(N/2);
figure;
plot(freq_ax_Hz(1:N_2), 10*log10(X_mags(1:N_2)));
xlabel('Frequency (Hz)')
ylabel('Amplitude (dB)');

It looks good but the plot is partially drawn into minus dB. 看起来不错,但该图被部分画成负dB。 Can someone show me how to correctly draw the spectrum in decibels? 有人可以告诉我如何正确绘制分贝频谱吗?

For your first plot, I notice you're only plotting the first half of the signal. 对于您的第一个图,我注意到您只是在绘制信号的前半部分。 Another, maybe easier way to do this is with fftshift : 另一个可能更简单的方法是使用fftshift

>> Xmag = fftshift(abs(fft(x)));

Now the DC value is in the middle rather than at the beginning. 现在,DC值在中间而不是开始。 The frequency vector is (-N/2:N/2 - 1)*fs/N 频率向量为(-N/2:N/2 - 1)*fs/N

If your signal is not symmetric, then you need to look at the negative values. 如果信号不对称,则需要查看负值。

For the second, note that dB requires 20*log10 unless you take the square of Xmag . 对于第二点,请注意,除非您采用Xmag平方 ,否则dB需要20*log10 Not a big deal, just a scalar, but thought you'd want to know. 没什么大不了的,只是一个标量,但是以为您想知道。

Also, minus dB are defined and expected. 此外,负dB的定义和预期。 The log(-1) is not defined for real numbers, but log(.1) or any other number less than 1 returns a negative answer. log(-1)没有为实数定义,但是log(.1)或任何其他小于1的数返回否定答案。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM