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

5 visualizzazioni (ultimi 30 giorni)
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 Commenti
Walter Roberson
Walter Roberson il 21 Lug 2019
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 il 21 Lug 2019
Ah I see.
I misunerstood that both should have the same format.
Thanks for clarifying

Accedi per commentare.

Risposta accettata

Star Strider
Star Strider il 21 Lug 2019
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.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by