Report#

Submit one set of handwritten answers per group at 12:30.

These questions on paper for the last hour (11:30-12:30h) of this session assess your understanding of the subject, your mathematical reasoning and insight, as well as interpretation of results, not your ability to recall specific Python syntax. There are five questions.

Computers, phones, online resources and AI tools are not permitted. You may use only handwritten notes prepared earlier in the session. Show the formulas and reasoning that support your answers; numerical or graphical answers without an explanation will not receive full credit.

Short re-cap of section 3.4 on sampling from the MUDE textbook#

The Fourier transform of continuous-time signal \(x(t)\) is \(X(f)\) as a function of frequency \(f\). The Fourier transform of the (impulse train) sampled signal \(x_s(t)\) is

\[X_s(f)=\sum_{k=-\infty}^{\infty} X(f-kf_s) \hspace{10px} \textrm{with } k \in \mathbb{Z}\]

so, the spectrum of the sampled signal is the spectrum of the original signal, but repeated with “period” \(f_s\) (in the frequency domain); copies of spectrum are called aliases.

sampled

Spectrum of an assumed original signal \(x(t)\) (left) and that of its sampled equivalent (right)

Full re-cap of section 3.5 on Discrete Fourier Transform from the MUDE textbook#

Discrete time Fourier Transform (DTFT)#

We discretize Fourier transform of \(x_s(t)\)

\[X_s(f)=\int_{-\infty}^{\infty}x_s(t)e^{-j2\pi ft}dt\]

by replacing the integral by summation over time:

\[X_s(f)=\sum_{n=-\infty}^{\infty}\Delta tx_ne^{-j2\pi fn\Delta t}\]

with \(x_n=x(n\Delta t)\) and where complex exponential is also evaluated at times \(t=n\Delta t\), and \(n\in\mathbb{Z}\).

This is still a continuous function of frequency \(f\) (\(f\in\mathbb{R}\)), periodic with period \(f_s\), exactly as we got with impulse train sampling, and known as Discrete Time Fourier Transform (DTFT).

In the example below we use \(x(t)=\textrm{sinc}^{2}(t)\) as an arbitrary, but very convenient signal, to demonstrate the impact of sampling on the Fourier transform of a signal.

This figure shows (continuous-time) signal \(x(t)\) at left, and the corresponding Fourier transform \(X(f)\) at right (in this case, very convenient, the Fourier transform is a real-valued function, not complex). Next, signal \(x(t)\) is sampled, and the resulting \(x_s(t)\) is shown below by the stems. The same range for the horizontal axis is used as before, but it has been stretched for better visibility. The sampling frequency is \(f_s = 3\) Hz.

Finally the Fourier transform \(X_s(f)\) of sampled signal \(x_s(t)\) is shown below. One can clearly see that the Fourier transform \(X_s(f)\) consists of many copies of the original Fourier transform \(X(f)\); these copies occur every integer multiple of the sampling frequency \(f_s\) (here \(f_s=3\) Hz). Acknowledging this finding, one would, in practice, need to consider only one period of this particular function (the rest consists of repetitions anyway); so for instance consider just the frequency range \([0,f_s)\) or \([-\frac{f_s}{2},\frac{f_s}{2})\). We will meet these particular choices again below, with the Discrete Fourier Transform (DFT).

Discrete Fourier Transform (DFT)#

We want to analyze spectrum \(X_s(f)\) of sampled signal \(x_s(t)\) using a computer, i.e. by Digital Signal Processing (DSP). Two issues remain, however:

\[X_s(f)=\sum_{n=-\infty}^{\infty}\Delta tx_ne^{-j2\pi fn\Delta t}\]
  • we cannot measure the signal forever, so we cannot have \(n\to\infty\)

  • once sampled in time domain, still continuous function (of frequency) does not lend itself to DSP - algorithm requires discrete data points as input, and delivers discrete data points as output

Action item 1 - we cannot measure signal forever

Sampled signal \(x_s(t)\) is a sequence \(x_n\) with \(n=\{-\infty,...,\infty\}\), so values \(x_n=x(n\Delta t)\) at discrete times \(t=n\Delta t\) (with \(n\in\mathbb{Z}\)).

We consider it only for time duration \(T=N\Delta t\), resulting in just N samples; effectively this means applying a window \(\Pi\left(\frac{t}{T}\right)\); in practice we set the signal to zero outside window, hence: \(x_{sw}(t)=\Pi\left(\frac{t}{T}\right)x_s(t)\)

This means \(x_n\) with \(n=0,...,N-1\) has finite length

Action item 2 - continuous function does not lend itself to DSP

‘Sample’ the frequency spectrum: we will evaluate it only at discrete frequencies.

As we only use piece of \(T=N\Delta t\) of the signal in time domain, the smallest resulting frequency is frequency step-size \(\Delta f\) and referred to as frequency (or spectral) resolution

\[\Delta f=\frac{1}{T}=\frac{1}{N\Delta t}=\frac{f_s}{N}\]

showing that the interval \([0,f_s)\) in the frequency domain is divided into \(N\) equal steps \(\Delta f\). Remember that \(X_s(f)\) is periodic with period \(f_s=\frac{1}{\Delta t}\), hence considering just the interval \([0,f_s)\) is sufficient, as the function \(X_s(f)\) is repeating. Hence, the spectrum will be computed at frequencies

\[f=0,\frac{1}{N}f_s,\frac{2}{N}f_s,...,\frac{N-1}{N}f_s\]

This results in the so-called Discrete Fourier Transform (DFT). DFT turns \(N\) samples of signal \(x(t)\) into \(N\) samples of spectrum \(X_{sw}(f)\):

\[x(n\Delta t) \leftrightarrow X_{sw}(k \Delta f)\]

with both \(n\) and \(k\in\{0,1,...,N-1\}\).

Going back to our action items:

Action item 1:

Sampled, windowed signal \(x_{sw}(t)\) equals sequence \(x_n\) with \(n=0,1,...,N-1\). Then, \(X_{sw}(f)=\int_{-\infty}^{\infty}x_{sw}(t)e^{-j2\pi ft}dt\), which we discretize with step size \(\Delta t\) into:

\[X_{sw}(f)=\sum_{n=0}^{N-1}\Delta t\,x_ne^{-j2\pi fn\Delta t}\]

Action item 2:

Finally, we ‘sample’ the frequency spectrum, turning \(X_{sw}(f)\) into \(X_{sws}(f)\) by considering only \(f=k\Delta f\) with \(\Delta f=\frac{1}{T}=\frac{1}{N\Delta t}=\frac{f_s}{N}\) and \(k=0,1,...,N-1\):

\[X_{sws}(k\Delta f)=\Delta t\sum_{n=0}^{N-1}x_ne^{-j2\pi k\Delta fn\Delta t}=\Delta t\sum_{n=0}^{N-1}x_ne^{-j\frac{2\pi}{N}kn},\hspace{5px}\text{with }k\in\mathbb{Z}\]

Hence sequence \(X_k\) equals \(X_{sws}(f)\) at \(f=k\Delta f\) for \(k=0,1,...,N-1\):

\[X_k=\Delta t\sum_{n=0}^{N-1}x_ne^{-j\frac{2\pi}{N}kn}\]

This is the discrete Fourier transform (DFT), typically implemented in software packages as fft (in Python, we will use numpy.fft.fft), though implemented without factor \(\Delta t\).

Inverse Fourier Transform (IDFT)#

The Inverse Fourier Transform reads \(x(t)=\int_{-\infty}^{\infty}X(f)e^{j2\pi ft}df\). Applying it to the sequence \(X_k\) and discretizing the integral yields:

\[x_{sws}(t)=\sum_{k=0}^{N-1}\Delta fX_ke^{j2\pi k\Delta ft}\]

Considering sampling in the time domain as \(t=n\Delta t\):

\[x_n=\sum_{k=0}^{N-1}\Delta fX_ke^{j2\pi k\Delta fn\Delta t}=\Delta f\sum_{k=0}^{N-1}X_ke^{j\frac{2\pi}{N}kn}=\frac{1}{N\Delta t}\sum_{k=0}^{N-1}X_ke^{j\frac{2\pi}{N}kn}\]

Summary#

\[\begin{split} \begin{aligned} X_k &= \Delta t\sum_{n=0}^{N-1}x_ne^{-j\frac{2\pi}{N}kn}\\ x_n &= \frac{1}{N\Delta t}\sum_{k=0}^{N-1}X_ke^{j\frac{2\pi}{N}kn} \end{aligned} \end{split}\]

with both \(k\) and \(n\in\{0,1,...,N-1\}\)

With \(X_k\), we consider function \(X(k\Delta f)\) by restoring frequency dimension, frequency step-size, \(\Delta f=\frac{1}{T}=\frac{1}{N\Delta t}=\frac{f_s}{N}\)

With \(x_n\), we consider function \(x(n\Delta t)\) by restoring time dimension, with time step \(\Delta t=\frac{1}{f_s}\)

In many textbooks we find the DFT as:

\[\begin{split} \begin{aligned} X_k &= \sum_{n=0}^{N-1}x_ne^{-j\frac{2\pi}{N}kn}\\ x_n &= \frac{1}{N}\sum_{k=0}^{N-1}X_ke^{j\frac{2\pi}{N}kn} \end{aligned} \end{split}\]

with both \(k\) and \(n\in\{0,1,...,N-1\}\)

Hence, without factors \(\Delta t\) and \(\frac{1}{\Delta t}\). This is also how DFT is implemented in programming languages like Matlab and Python; the user has to restore time and frequency dimension!

Re-cap of the Python notebook#

In Task 2 you used continuous-time signal \(x(t) = A \sin (2 \pi f_c t + \phi)\) with amplitude \(A=1\) V, carrier frequency \(f_c=1\) Hz, and phase offset \(\phi=5^o\) (converted into radians). This is a plain (undamped) sinusoid. This signal was observed/measured for a duration of \(T_{meas}=5.0\) s and sampled at \(f_s=100\) Hz, giving exactly \(N=500\) discrete-time samples \(x_n\), with \(n=0,\ldots,N-1\). The sampled signal is shown below, the samples are connected by line-segments.

DTsignal

Sampled signal \(x_s(t)\), i.e. samples \(x_0, x_1, \ldots, x_{N-1}\), shown as a function of time \(t\), with \(t=n \Delta t\) in seconds.

The Python np.fft.fft turns these \(N\) samples of the signal, into \(N\) ‘samples’ of the signal’s Fourier transform \(X_k\) with \(k=0,\ldots,N-1\). The magnitude \(|X_k|\), using np.abs, is shown in the graphs below. The result of Python’s np.fft.fft has actually been divided by \(N\), as to align the amplitude with the continuous-time Fourier transform, but this is not relevant here.

DFTofDTsignal

Magnitude of Discrete Fourier Transform (DFT) result \(\lvert X_k \rvert \), at left in log-log-scale, at right in linear scale

Question 1#

The horizontal axes of the above plots (from Task 2 in the Python notebook) range from \([0,f_s)\) (indeed, in the log-log plot the value \(f=0\) has actually been omitted, as this is problematic in terms of a logarithm; the horizontal axis starts from \(0.1\) Hz instead).

Explain why the Fourier transform output in Python covers just \([0,f_s)\) rather than the entire frequency-axis from \(f=-\infty\) to \(\infty\).

Question 2#

Instead of using Python, you’ll now do a Discrete Fourier Transform (DFT) on a simple signal yourself.

A zero initial phase \(\phi=0\), unit-amplitude, cosine \(x(t)=\cos(2 \pi f_c t)\) with carrier frequency \(f_c=1\) Hz, has been measured for \(T_{meas}=2\) s, with a sampling frequency of \(f_s=10\) Hz. As a result, there are \(N=20\) discrete-time samples. These samples are input to the Python np.fft.fft. The result is divided by \(N\) (though not really relevant here), and the modulus is taken, resulting in \(|X_k|\) with \(k=0,\ldots,N-1\).

Create a plot of the magnitude spectrum \(|X_k|\) as a function of index \(k\) on the horizontal axis, in linear scale. So, we (you) do plt.plot(np.abs(Xk)/N). How does the result look like? Include your (hand-drawn) sketch of the resulting plot in your report. Please plot (and mark) all N output values, also the zero ones.

Question 3#

Does aliasing occurs while sampling the signal in this case, of Question 2? Why, or why not?

Question 4#

Now we repeat the above Question 2, but instead of \(f_s=10\) Hz, we now use \(f_s=5\) Hz (the values of all other parameters stays the same, except for \(N\) which now is \(N=10\) discrete time samples).

Provide the output of the DFT, i.e. a graph of \(|X_k|\) as a function of index \(k\) (just as with Question 2). Again plot (and mark) all N output values, also the zero ones.

Question 5#

Finally we extend the case of the Question 4. The sampling frequency stays at \(f_s=5\) Hz and we still measure the signal for \(T=2\) s. The signal however now consists of TWO plain cosine signals (both unit amplitude and zero initial phase): \(x(t)=\cos(2 \pi f_1 t) + \cos(2 \pi f_2 t)\) with \(f_1=1\) Hz as in Question 4, and \(f_2=3\) Hz.

Provide the output of the DFT, i.e. a graph of \(|X_k|\) as a function of index \(k\) (just as with Question 4). Again plot (and mark) all N output values, also the zero ones.

How did things go? (Optional)#

After the session, your group may share feedback with us (i.e. the teaching team) about the notebook and the written questions. You can also use this space to let us know if you ran into challenges while working on this GA, and if you have any feedback to report.

By Christian Tiberius, Delft University of Technology. CC BY 4.0, more info on the Credits page of Workbook.