Fourier Series Sum Code Check
10 ビュー (過去 30 日間)
古いコメントを表示
Could I please ask for some assistance with the following piece of code.
I have manually calculated the fourier transform which is below. I deliberately chose n <= 100. The problem I am experiencing is the amplitude. I expect the the amplitude to be from -1 to 1 as I have proven this by performing a piecewise plot where the function was defined between -2 & 2, however it is only -0.4 to 0.4. If I change the first term in the equation from 1/2 to 1/100 I get the amplitude I am after, however I am wondering if there is something I have done with the code that I cannot see which is the reason the plot has a reduced amplitude using the derived equation. Maybe there is an issue with calculations, but I would appreciate if a far more experienced Matlab user could confirm if I have coded correctly.
%Fourier Series
%Function is defined on the interval -2<=t<=2
%f(t) =(-t-1) when -2<=t<=0 & (t-1) when 0<=t<=2
%Plot function over the interval -8<=t<=8
t=-8:2:8; %Define interval
ft=0; %Define variables
n=1;
while n<=100 %Count real numbers
%Fourier Transform written as a definite sum
ft=ft+((1/2)-(8/pi.^2))*cos((2*n-1)*pi*t/2)./(2*n-1).^2;
n=n+1;
end
plot(t,ft)
grid on;hold on;
5 件のコメント
Jonas
2021 年 5 月 23 日
hi Dan, congratulations to your solution. now you can put your own developed answer (with corrected code and explanation) below your question and accept it as your own answer, then this questions is sorted into the category 'answered'. good work and good luck with your next task!
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!