I'm trying to get the fourier series function(s) to work for a square wave with duty cycles other than 50% ie rectangular wave.

squareWave[t_, period_, duty_] := UnitBox[Mod[t/period, 1.]/(2. duty)]    
xx[t_] := squareWave[t, 10, 0.8]    
Plot[xx[t], {t, -10, 10}, Background -> Gray]
curvexx = FourierTrigSeries[xx[t], t, 10];  
Plot[curvexx, {t, -10, 10}, Background -> Gray]

that's my code, set up squarewave, check by plotting (alright so far), take fourier series, check by plotting and it's wrong but why where did I go wrong?

  • 1
    $\begingroup$ Your code is incomplete. squareWave is not defined. Please post complete code: it should be possible to just copy and paste to test it. $\endgroup$ – Szabolcs Jun 16 '14 at 15:26
  • 3
    $\begingroup$ @Öskå Maybe. But that's not what the OP wrote. Not posting complete code and not posting the same code that produced the error already wastes too much time on this site. $\endgroup$ – Szabolcs Jun 16 '14 at 15:27
  • $\begingroup$ forgot to paste squareWave[t_, period_, duty_] := UnitBox[Mod[t/period, 1.]/(2. duty)] but really it aint a crime $\endgroup$ – onepound Jun 16 '14 at 15:43
  • $\begingroup$ @user15970 - FourierTrigSeries doesn't accept the FourierParameters-Option. Eliminate that and you get at least a nice image :) $\endgroup$ – eldo Jun 16 '14 at 15:47
  • $\begingroup$ @eldo Actually it does. The red colouring is not correct. $\endgroup$ – Szabolcs Jun 16 '14 at 15:52

FourierTrigSeries essentially truncates the domain of the function to the interval $(-\pi,\pi)$. In other words, it assumes that the period of the function is $2\pi$. If this is not the case, you need to use FourierParameters to change this interval. FourierParameters -> {1,b} uses $(-\pi/b, \pi/b)$, so for a function of period p you need to use FourierParameters -> {1, 2Pi/p}, i.e. in your case use FourierParameters -> {1,Pi/5}.


I'm not well-versed in Fourier analysis, but your problem seems to stem from the choice of period. FourierTrigSeries appears to be assuming a period of 2 π

squareWave[period_, duty_] := UnitBox[Mod[t/period, 1.]/(2. duty)]
xx[t_] := squareWave[2 Pi, 0.8]
Plot[xx[t], {t, -10, 10}]
curvexx = FourierTrigSeries[xx[t], t, 8];
Plot[curvexx, {t, -10, 10}]



  • $\begingroup$ there is an option FourierParameters to modify the period. $\endgroup$ – george2079 Jun 17 '14 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.