필터 지우기
필터 지우기

Plotting the frequency spectrum / didnt understand the code

조회 수: 3 (최근 30일)
qusay hawari
qusay hawari 2015년 1월 17일
댓글: qusay hawari 2015년 1월 17일
X_mags = abs(fftshift(fft(signal)));
bin_vals = [0 : N-1];
N_2 = ceil(N/2);
fax_Hz = (bin_vals-N_2)*fs/N;
plot(fax_Hz, X_mags)

채택된 답변

Geoff Hayes
Geoff Hayes 2015년 1월 17일
Qusay - let us assume the following concerning your signal, sampling rate (Fs), and FFT block size (N)
Fs = 4096; % sampling rate in Hertz
t = linspace(0,1-1/Fs,Fs); % one second time vector given Fs
N = 4096; % FFT block size is same as sampling rate (true for your ex)
signal = 2.3*sin(2*pi*t*227); % signal with amplitude of 2.3 and frequency of 227 Hertz
Now for your code
% transforms the signal from the time domain to the frequency domain with fft
% note that y is complex
Y = fft(signal);
% shifts the frequency components so that the zero frequency is at the centre
% of spectrum
Y = fftshift(Y);
% determines the magnitude of the complex data
Y = abs(Y);
The following lines of code just sets the frequencies for each bin and can be reduced to
f = [0:N-1] * Fs/N;
% must ensure that zero is the centre frequency due to our fftshift from above
f = f - ceil(N/2);
% plot the data
plot(f,Y);
The result of the plot is
Note the frequency at 227 Hz, as expected. The symmetry is due to the input signal being real.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Pulsed Waveforms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by