フィルターのクリア

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 Center および File ExchangeSpectral Measurements についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by