I Wrote a Code For Fast Fourier Transformation With a Sin Function

5 Ansichten (letzte 30 Tage)
I created a code plots a sin(2*pi*f*t) function in t=-4:0.001:4 with period (T) 5ms.
Then by using Fast Fourier Transformation (FFT), I converted the function from time domain to frequency domain and plotted it.
Here is my code that I have written:
Did I do correctly or Do I have a mistake?
fs = 1000; %sampling freq.
t = -4 : 1/fs : 4; %period which is between -4 to 4
f = 200;
x = sin(2*pi*f*t); %function is time domain
n = length(t); %length of interval
Fou_x = (fft(x)); %fourier transform of function
Foushift_x = fftshift(Fou_x); %shift to zero
finterval = fs/n; %increasing value of freq. interval
f = -fs/2 : finterval : fs/2-finterval; %freq. interval
figure;
plot(f, abs(Foushift_x)/n); %plot freq. function interval
xlabel('Frequency (in Hertz');
title('Magnitude');

Akzeptierte Antwort

Benjamin Thompson
Benjamin Thompson am 2 Mär. 2022
Looks correct. The amplitude of your input signal is divided between the left and right half of the output. Type the command "doc fft" for a more detailed example.

Weitere Antworten (0)

Kategorien

Mehr zu Fourier Analysis and Filtering finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by