簡體   English   中英

在MATLAB中繪制256點FFT的頻譜

[英]plotting the spectrum of a 256 point FFT in matlab

我已經計算出頻率為1kHz,峰峰值為2V的純正弦波的256點FFT,我已經獲得256個FFT系數,現在我必須繪制其頻譜,如何使用Matlab繪制它?不是使用Matlab生成的。請提供幫助。 提前致謝。

為了繪制FFT系數的頻譜,您需要以下信息:

  • 采樣頻率
  • 256個FFT系數

首先,您將256個系數加載到MATLAB變量中。 例如,如果將系數另存為變量y_fft ,那么以下代碼行將為您繪制光譜:

% plotting of spectra
p  = abs(y_fft.^2) ;
df = Fs/Npoint_fft ;
ff = 0:df:Fs/2-df ;
figure
plot (ff,p(1:end/2))

在上面的代碼中, Fs是采樣頻率, Npoint_fft等於256。

您可以在MATLAB中生成信號,然后繪制頻譜圖。 以下是一些用於信號生成和繪圖的代碼:

Fs = 20000 ;
duration = 0.001 ;
t = 0: 1/Fs:duration-(1/Fs) ;
f  = 1000 ;
Npoint_fft = 256 ;

% creation and plotting of signal of 1KHz
y = sin (2 * pi * f * t) ;
plot (t,y)

% 256 point fft
y_fft = fft(y,256) ;

% plotting of spectra
p  = abs(y_fft.^2) ;
df = Fs/Npoint_fft ;
ff = 0:df:Fs/2-df ;
figure
plot (ff,p(1:end/2))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM