MATLAB: How to plot Fourier series with 100 terms

fourierplotseries

I'm trying to plot the attached Fourier series for 100 terms but the plot shows values reaching 40 when I'm expecting maximum values to be around 4. This is what I've managed so far. I would appreciate if someone could help me understand where I'm going wrong
t=-pi:pi/10:pi;
vt=zeros(1,length(t));
for m=1:1:2;
bm=(8/m*pi)*(1-cos(m*pi/2))
vt= vt + bm*sin(m*t);
end
plot(t,vt)

Best Answer

for m=1:1:2;
And you think this makes 100 terms??
Then
bm=(8/m*pi)*(1-cos(m*pi/2))
So you multiply by pi? Look like you need to concentrate on the parenthesis:
bm=8/(m*pi)*(1-cos(m*pi/2));
Related Question