Equation for Fourier Series
Mostra commenti meno recenti
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:

Risposta accettata
Più risposte (1)
Romain Boutant
il 10 Apr 2021
1 voto
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.
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!