필터 지우기
필터 지우기

Hello, I am trying to plot the fourier series of a function but it doesnt seem to be giving me anything near the graph of the original fuction.

조회 수: 3 (최근 30일)
t = -pi: 0.0001 : pi
total = 0.5
for n = 1:1:100
an = -1*((-1)^n)+1 /pi*((n)^2);
bn = -exp(1)*n*((-1)^n) - pi*n*((-1)^n) + 4*n*((-1)^n) - (4*n) + (exp(1)*n) /pi*n^2;
total = total + an*cos(n*t) + bn*sin(n*t);
end
a0 = (-pi/2)+4+exp(1);
total = total*a0;
plot(t,total)
  댓글 수: 3
Rohan Sabherwal
Rohan Sabherwal 2020년 11월 12일
I have tried to change it but keep getting something completely off, I tried looking over my working out for the fourier series and it seems to be okay.
Bjorn Gustavsson
Bjorn Gustavsson 2020년 11월 13일
Calculate and save the Fourier coefficient for all n and plot them - that way you can check that they behave in the way you expect/intend.
HTH

댓글을 달려면 로그인하십시오.

답변 (1개)

Setsuna Yuuki.
Setsuna Yuuki. 2020년 11월 13일
What is the waveform it is supposed to give? Did you try a simpler function?
I tried with this code: (Sawtooth wave)
t= 0:1e-3:5;
sumatoria = 0;
serie = 0;
for n = 1:1:15
serie=1/pi*1/n*sin(2*n*pi*t);
sumatoria = serie+sumatoria;
end
sumatoria = 1/2-sumatoria;
plot(t,sumatoria)

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by