Plotting the Fourier series for the function f=pi+x
조회 수: 5 (최근 30일)
이전 댓글 표시
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:
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
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
채택된 답변
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.
댓글 수: 2
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Frequency Transformations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!