Skip to main content
1-Visitor
March 9, 2021
Solved

Fourier series of a half symmetrical wave not working

  • March 9, 2021
  • 3 replies
  • 6425 views

Hi all,

My job is to find and plot the Fourier series of the wave(figure 8.png) up to a sensible n value.

 

Problems:

1- When I try to compute the f(t) using the symbolic engine it gives me (Error 1 and 2.png)

2- When I try to plot this, I get another error something along the lines of plot failed because of 'complex and Nans' or something along those lines.

 

I have attached my file and used legacy symbolic engine but still does not work.

Best answer by LucMeekes

But on closer observation, the problems are clear:

You defined f to be a function of 2 parameters: n and t.

Now n is used as a parameter to the function, but also as a running variable in the summation. Prime is fully in its right to complain.

When plotting it, you only supply a single parameter f(t)...

 

Does this come close?

LucMeekes_0-1615325046948.png

 

 

Success!
Luc

3 replies

23-Emerald IV
March 9, 2021

 

Prime (as well as real mathcad) does not plot complex, imaginary or Not A numbers.

You've probably run into complex or imaginary numbers. You can see what's going on by plotting the Real  and/or the Imaginary parts of the complex numbers. Use functions Re() and Im() to extract those parts for plotting.

 

Success!
Luc

 

LucMeekes23-Emerald IVAnswer
23-Emerald IV
March 9, 2021

But on closer observation, the problems are clear:

You defined f to be a function of 2 parameters: n and t.

Now n is used as a parameter to the function, but also as a running variable in the summation. Prime is fully in its right to complain.

When plotting it, you only supply a single parameter f(t)...

 

Does this come close?

LucMeekes_0-1615325046948.png

 

 

Success!
Luc

1-Visitor
March 9, 2021

Thanks man,

I removed f(t,n) to f(t) (note: I now changed t to theta because horizontal axis is supposed to be rad not seconds).

 

Having said that, there is still a problem that the max amplitude is around 1.5 not 1 volt as required. What might be the problem there? Have a look, I have attached an updated file. 

 

(UPDATE: the previous errors regarding the symbolic engine disappeared upon restarting the program)

23-Emerald IV
March 9, 2021

I see the cause of the problem.

Your signal is supposed to go down from 0 to -1 in the period for t between 0 and pi.

Does the function -t/pi do that for this range of values of t  ?

Then from pi on, the function should go up from 0 to 1.

Does the function t/pi do that for the range of values of t from pi to 2pi ?

 

This should help you find the cause, and solve the problem.

 

Success!
Luc

 

23-Emerald I
March 9, 2021

You don't need symbolics, but you do need to keep track of how many arguments your functions need.

1-Visitor
March 9, 2021

Excellent response! 

I had a look at the 'weird fourier' file and am impressed by it. You have used vector to store the Fourier coefficient(harmonics). For some reason it works way faster than the other file and can calculate up 200 n in only a few seconds where-as my other file takes a long time. 

15-Moonstone
March 9, 2021