필터 지우기
필터 지우기

Does this plot look right?

조회 수: 4 (최근 30일)
Kenzie
Kenzie 2024년 2월 6일
답변: Voss 2024년 2월 6일
I am making an fft of a sine wave, and the amplitude spectra looks sharper than I thought it would be. So, what I'm wondering is if there is something wrong with my code, or if the fft of a sine wave looks like this when the sampling frequency is 100 hz with 300 samples.
% Define the time vector
Fs = 100; % Sampling frequency (Hz)
T = 1/Fs; % Sample time
t = 0:T:(299*T); % Time vector with 300 samples and a sample interval of 0.01 seconds
% Create a sine wave with a period of 1 second
f = 1; % Frequency of the sine wave (Hz)
x = sin(2*pi*f*t);
% Calculate the FFT
N = length(x); % Length of the signal
frequencies = Fs*(0:(N/2))/N; % Frequency vector
X = fft(x); % FFT of the signal
amplitude = 2/N * abs(X(1:N/2+1)); % Amplitude of the positive frequencies
% Plot the amplitude against frequency
figure;
plot(frequencies, amplitude);
title('FFT of Sine Wave');
xlabel('Frequency (Hz)');
ylabel('Amplitude');
grid on;
% Set x-axis limit to zoom in on frequencies between 0 and 5 Hz
xlim([0 5]);

채택된 답변

Walter Roberson
Walter Roberson 2024년 2월 6일
You have a source signal that consists of a single frequency. The theoretical outcome for the fourier transform is all zero everywhere except at the exact frequency of the sine wave. That gets approximated with an fft, ending up with a triangle wave.

추가 답변 (1개)

Voss
Voss 2024년 2월 6일
It is ok. You can see more clearly that the signal has content only at 1Hz by using a stem plot:
% Define the time vector
Fs = 100; % Sampling frequency (Hz)
T = 1/Fs; % Sample time
t = 0:T:(299*T); % Time vector with 300 samples and a sample interval of 0.01 seconds
% Create a sine wave with a period of 1 second
f = 1; % Frequency of the sine wave (Hz)
x = sin(2*pi*f*t);
% Calculate the FFT
N = length(x); % Length of the signal
frequencies = Fs*(0:(N/2))/N; % Frequency vector
X = fft(x); % FFT of the signal
amplitude = 2/N * abs(X(1:N/2+1)); % Amplitude of the positive frequencies
% Plot the amplitude against frequency
figure;
% plot(frequencies, amplitude);
stem(frequencies, amplitude);
title('FFT of Sine Wave');
xlabel('Frequency (Hz)');
ylabel('Amplitude');
grid on;
% Set x-axis limit to zoom in on frequencies between 0 and 5 Hz
xlim([0 5]);

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by