I Wrote a Code For Fast Fourier Transformation With a Sin Function
조회 수: 5 (최근 30일)
이전 댓글 표시
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');
댓글 수: 0
채택된 답변
Benjamin Thompson
2022년 3월 2일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!