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?


squareWaveis not defined. Please post complete code: it should be possible to just copy and paste to test it. – Szabolcs Jun 16 '14 at 15:26FourierTrigSeriesdoesn't accept theFourierParameters-Option. Eliminate that and you get at least a nice image :) – eldo Jun 16 '14 at 15:47FourierParameters -> {1, Pi/5}. Why did you chooseFourierParameters -> {1, π/2}? – Szabolcs Jun 16 '14 at 15:52FourierTrigSeriescarefully, especially under the Details section where it is precisely defined what this function does, and howFourierParametersaffect the result. You'll see that your choice ofFourierParametersmust match the period. – Szabolcs Jun 16 '14 at 15:57FourierTrigSeriesessentially truncates the function to the interval $(-\pi, \pi)$. By usingFourierParameters -> {1, Pi/5}this is extended to $(-5, 5)$. Just make sure the interval width is equal to the period (or possibly an integer multiple of it). My original suggestion ofPi/10makes it 2x larger, soPi/5is better. – Szabolcs Jun 16 '14 at 16:02