Plotting the Fourier series for the function f=pi+x

조회 수: 5 (최근 30일)
Charith Silva
Charith Silva 2019년 7월 21일
댓글: Star Strider 2019년 7월 23일
I was trying to plot the Fourier series representation of the graph of (which should be a straight line).
And the Fourier series representation is given as:
Capture.JPG
This is the code that I'm using: ()
x=-pi:0.01:pi;
y=x+pi
Fr=0;
for i=1:100
an=((-1)*(i+1)*sin(i*x))/i;
Fr=Fr+2*an;
end
Fr=Fr+pi;
plot(x,Fr)
But I'm getting a graph no where close to a straight line.
A help would be highly appreciated
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 7월 21일
The original is a straight line. The fourier transform of it is a delta function
https://dsp.stackexchange.com/questions/36552/fourier-transform-of-a-tilted-line-function
Charith Silva
Charith Silva 2019년 7월 21일
Ah I see.
I misunerstood that both should have the same format.
Thanks for clarifying

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

채택된 답변

Star Strider
Star Strider 2019년 7월 21일
You forgot to raise (-1) to a power. (You multiplied it instead.)
Try this:
an=((-1).^(i+1)*sin(i*x))/i;
Also, more terms produces a smoother plot.
To check the result, I did it without a loop:
n = 1:1E+3;
F = pi + 2*sum(sin(n(:)*x).*(-1).^(n(:)+1)./n(:));
figure
plot(x, F)
producing essentially the same plot.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Frequency Transformations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by