Does this plot look right?
조회 수: 4 (최근 30일)
이전 댓글 표시
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]);
댓글 수: 0
채택된 답변
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.
댓글 수: 0
추가 답변 (1개)
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]);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spectral Measurements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!