Does this plot look right?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Walter Roberson
le 6 Fév 2024
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 commentaires
Plus de réponses (1)
Voss
le 6 Fév 2024
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 commentaires
Voir également
Catégories
En savoir plus sur Spectral Measurements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!