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

5 views (last 30 days)
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');

Accepted Answer

Benjamin Thompson
Benjamin Thompson on 2 Mar 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.

More Answers (0)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!