Let's take a switch function as an example:
$ u(t)= \begin{cases} 1, & \text{$0<t<dT_s$} \\ 0, & \text{$dT_s<t<T_s$} \end{cases} $
How can I get Fourier series of it in Mathematica?
Is there a way to get Fourier series of arbitrary periodic piecewise function?

  • 2
    $\begingroup$ I would start by having a look at Piecewise and Fourier. $\endgroup$ Feb 26, 2019 at 9:09
  • $\begingroup$ @b.gatessucks You probably meant FourierSeries, right? Fourier is the discrete fourier transform (FFT). I am also puzzeld by the many different Fourier-related commands in Mathematica. $\endgroup$ Feb 26, 2019 at 10:11
  • $\begingroup$ @HenrikSchumacher Indeed, thanks for pointing that out. $\endgroup$ Feb 26, 2019 at 10:37
  • $\begingroup$ Strongly related, if not duplicate: mathematica.stackexchange.com/q/149468/1871 $\endgroup$
    – xzczd
    Feb 26, 2019 at 10:39
  • $\begingroup$ People here generally like users to post code as Mathematica code instead of just images or TeX, so they can copy-paste it. It makes it convenient for them and more likely you will get someone to help you. You may find this this meta Q&A helpful $\endgroup$
    – Michael E2
    Feb 26, 2019 at 14:29

2 Answers 2


for example:

u[t_] = Piecewise[{{1, 0 < t < dT}, {0, dT < t < T}}];
FourierTrigSeries[u[t], t, 3, FourierParameters -> {1, 2 \[Pi]/T}, 
 Assumptions -> 0 < dT < T && 2 dT == T]

enter image description here


Try u[t_] := UnitStep[Sin[t]]; FourierSeries[u[x], x, 3] 3 is series

  • 1
    $\begingroup$ One might want to be mindful of the FourierParameters setting when using FourierSeries[] and other sundry functions, lest Mathematica's chosen normalization might not be the same as your preferred one. $\endgroup$ Feb 26, 2019 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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