# Fourier series for rectangular wave incorrect, why?

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?

• Your code is incomplete. squareWave is not defined. Please post complete code: it should be possible to just copy and paste to test it. Jun 16 '14 at 15:26
• @Ö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. Jun 16 '14 at 15:27
• forgot to paste squareWave[t_, period_, duty_] := UnitBox[Mod[t/period, 1.]/(2. duty)] but really it aint a crime Jun 16 '14 at 15:43
• @user15970 - FourierTrigSeries doesn't accept the FourierParameters-Option. Eliminate that and you get at least a nice image :)
– eldo
Jun 16 '14 at 15:47
• @eldo Actually it does. The red colouring is not correct. 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)]

• there is an option FourierParameters to modify the period. Jun 17 '14 at 12:27