フィルターのクリア

Equation for Fourier Series

3 ビュー (過去 30 日間)
Brendan Clark
Brendan Clark 2021 年 4 月 10 日
編集済み: David Goodmanson 2021 年 4 月 11 日
I'm working on an assignment that requires me to plot a truncated fourier series. I have it very close to being correct.
The code I have now is
clc;
clear all;
close all;
f_0=400000;
t=0:0.1*10^(-6):6*10^(-6);
sum=0;
for n=1:5
sum=sum+4/((2*pi)*n-1)*sin((2*pi)*(2*n-1)*f_0*t);
f(n,:)=sum;
end
figure;
subplot(2,2,1);
plot(t,f(2,:),'LineWidth',2);
title('N=2');
xlabel('t in u sec');
ylabel('f(t)');
subplot(2,2,2);
plot(t,f(3,:),'LineWidth',2);
title('N=3');
xlabel('t in u sec');
ylabel('f(t)');
subplot(2,2,3);
plot(t,f(4,:),'LineWidth',2);
title('N=4');
xlabel('t in u sec');
ylabel('f(t)');
subplot(2,2,4);
plot(t,f(5,:),'LineWidth',2);
title('N=5');
xlabel('t in u sec');
ylabel('f(t)');
The graph I have now looks like
I need it to look like
I'm struggling to figure out why my graph is all wonky.
This is the actual problem I'm working in full:

採用された回答

David Goodmanson
David Goodmanson 2021 年 4 月 11 日
編集済み: David Goodmanson 2021 年 4 月 11 日
Hi Romain,
increasing the nomber of points is a good idea. I used
t=0:0.01*10^(-6):6*10^(-6);
but I believe there is also a problem with the code, which instead of
sum=sum+4/((2*pi)*n-1)*sin((2*pi)*(2*n-1)*f_0*t);
should be
sum=sum+4/(pi*(2*n-1))*sin((2*pi)*(2*n-1)*f_0*t);

その他の回答 (1 件)

Romain Boutant
Romain Boutant 2021 年 4 月 10 日
Your code is fine, you just have to increase the number of points to match the theoretical curves.
A simple fix is t=0:0.1*10^(-7):6*10^(-6); at line 5.

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by