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]);

采纳的回答

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