【 MATLAB 】訊號處理工具箱之fft簡介及案例分析
阿新 • • 發佈:2018-11-11
目錄
Syntax
Y = fft(X)
Y = fft(X,n)
Y = fft(X,n,dim)
Description
Y = fft(X)
使用fast Fourier transform(FFT)演算法計算訊號X的離散傅立葉變換:Y
= fft(X
)
-
如果 X 是一個向量,那麼 fft(X) 返回向量的傅立葉變換;
-
如果 X 是一個矩陣,則 fft(X) 視X的列為向量,然後返回每列的傅立葉變換;
Y
= fft(X
,n
)
Y
= fft(X
,n
)
返回 n 點 DFT。 如果未指定任何值,則Y與X的大小相同。Y
= fft(X
,n
)
-
如果X是向量並且X的長度小於n,則用尾隨零填充X到長度n。
-
如果X是向量並且X的長度大於n,則X被截斷為長度n。
-
如果X是矩陣,那麼每個列都被視為向量情況。
-
如果X是多維陣列,則大小不等於1的第一個陣列維度將被視為向量的情況。
Y = fft(X,n,dim)
Y = fft(X,n,dim)沿維度dim返回傅立葉變換。 例如,如果X是矩陣,則fft(X,n,2)返回每行的n點傅立葉變換。
Examples
Noisy Signal
使用傅立葉變換來查詢隱藏在噪聲中的訊號的頻率分量。
指定取樣頻率為1 kHz且訊號持續時間為1.5秒的訊號引數。
clc clear close all % Use Fourier transforms to find the frequency components of a signal buried in noise. % Specify the parameters of a signal with a sampling frequency of 1 kHz and a signal duration of 1.5 seconds. Fs = 1000; % Sampling frequency T = 1/Fs; % Sampling period L = 1500; % Length of signal t = (0:L-1)*T; % Time vector % Form a signal containing a 50 Hz sinusoid of amplitude 0.7 and a 120 Hz sinusoid of amplitude 1. S = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t); % Corrupt the signal with zero-mean white noise with a variance of 4. X = S + 2*randn(size(t)); % Plot the noisy signal in the time domain. It is difficult to identify the frequency components by looking at the signal X(t). figure(); plot(1000*t(1:50),X(1:50)) title('Signal Corrupted with Zero-Mean Random Noise') xlabel('t (milliseconds)') ylabel('X(t)') % Compute the Fourier transform of the signal. Y = fft(X); % Compute the two-sided spectrum P2. Then compute the single-sided spectrum P1 based on P2 and the even-valued signal length L. P2 = abs(Y/L); P1 = P2(1:L/2+1); P1(2:end-1) = 2*P1(2:end-1); % Define the frequency domain f and plot the single-sided amplitude spectrum P1. % The amplitudes are not exactly at 0.7 and 1, as expected, because of the added noise. On average, % longer signals produce better frequency approximations. figure(); f = Fs*(0:(L/2))/L; plot(f,P1) title('Single-Sided Amplitude Spectrum of X(t)') xlabel('f (Hz)') ylabel('|P1(f)|') % Now, take the Fourier transform of the original, uncorrupted signal and retrieve the exact amplitudes, 0.7 and 1.0. % Y = fft(S); P2 = abs(Y/L); P1 = P2(1:L/2+1); P1(2:end-1) = 2*P1(2:end-1); figure(); plot(f,P1) title('Single-Sided Amplitude Spectrum of S(t)') xlabel('f (Hz)') ylabel('|P1(f)|')
figure(1)是加上零均值的隨機噪聲後的訊號時域圖形,通過觀察這幅圖很難辨別其頻率成分。
figure(2)是X(t)的單邊幅度譜,通過這幅圖其實已經能夠看出訊號的頻率成分,分別為50Hz和120Hz,其他的頻率成分都會噪聲的頻率分量。
figure(3)是訊號S(t)的單邊幅度譜,用作和figure(2)的幅度譜對比,原訊號確實只有兩個頻率成分。
上面三幅圖畫到一起:
更多案例見下篇博文:【 MATLAB 】訊號處理工具箱之 fft 案例分析