I have a discrete square wave $f(t)$ where $t \in \mathbb{N}$, of amplitude $A$, period $T$ and duty cycle $1/T$

$$ f(t) = \left\{\begin{matrix} A, & \mathrm{if}\;t=Tn\\ 0, & \mathrm{if}\;t\neq Tn \end{matrix}\right. \;,\; n \in \mathbb{N} $$

size = 23
T = 5
A = 10
t = np.arange(size)
f = np.zeros(size)
f[t%T==0] = A
fig, ax = plt.subplots(figsize=(12, 5))
ax.step(t, f)
    xlabel='time $t$',
    ylabel='amplitude $A$',
    title=f"Square wave of amplitude {A}, period {T} and duty cycle 1/{T}"

enter image description here

Given the Fourier series

$$ \mathcal{F}[g(t)] = a_0 + \sum_{h=1}^{\infty} a_h \cos(2 \pi h \nu \cdot t) - \sum_{h=1}^{\infty} b_h \sin(2 \pi h \nu \cdot t) $$

for this square wave

$$ a_0 = \frac{A}{T} $$

$$ a_h = \frac{2A}{\pi h} \sin \left( \frac{\pi h}{T} \right) $$

$$ b_h = 0 $$


$$ \mathcal{F}[f(t)] = \frac{A}{T} + \sum_{h=1}^{\infty} \frac{2A}{\pi h} \sin\left(\frac{\pi h}{T}\right) \cos\left(\frac{2 \pi h}{T} \cdot t\right) $$

where the Fourier coefficients of harmonic $h$ is $\frac{2A}{\pi h} \sin\left(\frac{\pi h}{T}\right)$.

The discrete difference of $f(t)$

$$ f'(t) = f(t) - f(t-1) $$

is the sum of two square waves $f(t)$ and $-f(t-1)$ with opposite amplitude and shifted by a sample unit

$$ f'(t) = \left\{\begin{matrix} +A, & \mathrm{if}\;t=Tn\\ -A, & \mathrm{if}\;t=Tn+1\\ 0, & \mathrm{otherwise} \end{matrix}\right. \;,\; n \in \mathbb{N} $$

t1 = t[1:]
f1 = np.diff(f)

fig, ax = plt.subplots(figsize=(12, 5))
ax.step(t1, f1)
    xlabel='time $t$',
    ylabel='amplitude $A$',
    title=f"Discrete difference of a square wave of amplitude {A}, period {T} and duty cycle 1/{T}"

enter image description here

We can thus say (is it correct?) that the Fourier series of $f'(t)$ is the sum of the Fourier series $\mathcal{F}[f(t)]$ and $\mathcal{F}[-f(t-1)]$

$$ \mathcal{F}[f'(t)] = \left[ \frac{A}{T} + \sum_{h=1}^{\infty} \frac{2A}{\pi h} \sin\left(\frac{\pi h}{T}\right) \cos\left(\frac{2 \pi h}{T} \cdot t\right) \right] - \left[ \frac{A}{T} + \sum_{h=1}^{\infty} \frac{2A}{\pi h} \sin\left(\frac{\pi h}{T}\right) \cos\left(\frac{2 \pi h}{T} \cdot (t-1)\right) \right] $$

$$ \mathcal{F}[f'(t)] = \sum_{h=1}^{\infty} \frac{2A}{\pi h} \sin\left( \frac{\pi h}{T}\right) \left[ \cos\left( \frac{2 \pi h}{T} \cdot t\right) - \cos\left( \frac{2 \pi h}{T} \cdot (t-1)\right) \right] $$

How can I get the Fourier coefficient of harmonic $h$ from $\mathcal{F}[f'(t)]$?

Is there a better way to express the Fourier series of $f'(t)$?


As @MattL. noticed (see comments) what I'm dealing with is actually a discrete-time signal, so a better representation of the signal would be

enter image description here

and for the discrete difference will look like

enter image description here

  • $\begingroup$ To me it's unclear if you're interested in the Fourier series of a continuous-time signal or of a discrete-time signal. In your definition you state that $t$ is a discrete variable, however, your formulation of the Fourier series is only appropriate for a continuous variable $t$. Also your plots seem to imply a continuous-time square wave, whereas your equation defines a discrete-time signal, which only equals $A$ for indices that are integer multiples of $T=5$. Could you clarify? $\endgroup$ – Matt L. Dec 28 '20 at 13:10
  • $\begingroup$ @MattL. thank you. Yes, time $t$ is discrete, data of the square wave are the results of $N$ theoretical observations every $\tau$ discrete time units (could be seconds, minutes, etc). How should I plot them? Can you point me to the correct Fourier series for a discrete-time signal? $\endgroup$ – Max Pierini Dec 28 '20 at 13:57
  • $\begingroup$ If $t$ is discrete then there's only a single value non-zero in each period, right? So, should we be talking about a square wave then? The Fourier series for a sequence (as opposed to a function) is actually identical (up to scaling and sign conventions) to the Discrete Fourier Transform (DFT). Note that unlike in the continuous case, the summation is only over one period ($N$ samples). $\endgroup$ – Matt L. Dec 28 '20 at 14:03
  • $\begingroup$ @MattL. Ah right. Thanks, I'll use DFT. $\endgroup$ – Max Pierini Dec 28 '20 at 14:45

It's quite straightforward to express the Fourier coefficients of a shifted version of a function in terms of the Fourier coefficients of the original function.

If the Fourier series of a $T$-periodic function $f(t)$ is given by

$$f(t)=\sum_{k=-\infty}^{\infty}c_ke^{j2\pi kt/T}\tag{1}$$

then it follows that the Fourier series of a shifted version must be

$$\begin{align}f(t-t_0)&=\sum_{k=-\infty}^{\infty}c_ke^{j2\pi k(t-t_0)/T}\\&=\sum_{k=-\infty}^{\infty}c_ke^{-j2\pi kt_0/T}e^{j2\pi kt/T}\\&=\sum_{k=-\infty}^{\infty}\tilde{c}_ke^{j2\pi kt/T}\tag{2}\end{align}$$

Hence, the Fourier coefficients of $f(t-t_0)$ are given by

$$\tilde{c}_k=c_ke^{-j2\pi kt_0/T}\tag{3}$$

And, by linearity, the Fourier series coefficients of $g(t)=f(t)-f(t-t_0)$ are

$$d_k=c_k-\tilde{c}_k=c_k\big(1-e^{-j2\pi kt_0/T}\big)\tag{4}$$

For periodic discrete-time sequences we can use the Discrete Fourier Tansform (DFT), which is just a discrete Fourier series representation:

$$x[n]=\frac{1}{N}\sum_{k=0}^{N-1}X[k]e^{j2\pi nk/N}\tag{5}$$


$$X[k]=\sum_{k=0}^{N-1}x[n]e^{-j2\pi nk/N}\tag{6}$$

In a completely analogous manner to the continuous-time case, we can derive an expression for the DFT coefficients of the sequence $y[n]=x[n]-x[n-n_0]$, $n_0\in\mathbb{Z}$:

$$Y[k]=X[k]\big(1-e^{-j2\pi n_0k/N}\big)\tag{7}$$

  • $\begingroup$ Thank you @matt-l exactly what I was looking for. $\endgroup$ – Max Pierini Dec 28 '20 at 14:44
  • $\begingroup$ i would add that to get the appropriate Fourier Series coefficients from the DFT coefficients that you have to compare Eqs. (5) and (1) carefully and use the latter half of the DFT $X[k]$ for the negative frequency $c_k$. $\endgroup$ – robert bristow-johnson Dec 28 '20 at 21:30

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.