Fourier series - Plot in Matlab

Thread Starter

xxxyyyba

Joined Aug 7, 2012
289
Hi!
Here is my m-file for Fourier series plot:

clear
clc
syms n
a0=input('Enter coefficient a0: ');
an=input('Enter coefficient an: ');
bn=input('Enter coefficient bn: ');
a=input('Enter lower boundary: ');
b=input('Enter upper boundary: ');
t=linspace(a,b,10000);
sum=0;
for n=1:100 %%n could be any number, bigger n - better approximation
sum=sum+(subs(an,'n',n).*cos(2.*n.*pi.*t./(b-a))+subs(bn,'n',n).*sin(2.*n.*pi.*t./(b-a)));
end
series=a0+sum;
plot(t,series)
grid

Problem is, it is so slow! What to do in order to increase speed?
 
Top