#!/usr/bin/env python # coding: utf-8 # # Spectral Analysis of Deterministic Signals # # *This jupyter notebook is part of a [collection of notebooks](../index.ipynb) on various topics of Digital Signal Processing. Please direct questions and suggestions to [Sascha.Spors@uni-rostock.de](mailto:Sascha.Spors@uni-rostock.de).* # ## Introduction # # Signals emerging from electrical/mechanical oscillatory systems have a specific structure. They are composed of a superposition of harmonic signals with different frequencies and amplitudes. Many practical signals are composed of (superpositions of) harmonic signals. [Estimating the number of harmonic signals, their frequencies, amplitudes, and phases](https://en.wikipedia.org/wiki/Modal_analysis) is an essential task in the analysis of unknown signals. In the practical realization of spectral analysis techniques, the [discrete Fourier transform](https://en.wikipedia.org/wiki/Discrete_Fourier_transform) (DFT) is applied to discrete finite-length signals to gain insights into their spectral composition. For instance, using a [Spectrum analyzer](https://en.wikipedia.org/wiki/Spectrum_analyzer). However, analyzing harmonic signals with the DFT is subject to fundamental limitations. These limitations are discussed in the following. # ## The Leakage Effect # # [Spectral leakage](https://en.wikipedia.org/wiki/Spectral_leakage) is a fundamental effect of the DFT. It limits the ability to detect harmonic signals in signal mixtures and hence the performance of spectral analysis. In order to discuss this effect, the DFT of a discrete exponential signal is revisited starting from the Fourier transform of the continuous exponential signal. The connections between the Fourier transform, the [discrete-time Fourier transform](https://en.wikipedia.org/wiki/Discrete-time_Fourier_transform) (DTFT) and the DFT for a uniformly sampled signal are illustrated below. # # ![Connections between the different Fourier transforms](Fourier_transforms.png) # # Consequently, the leakage effect is discussed in the remainder of this section by considering the following four steps: # # 1. Fourier transform of an harmonic exponential signal, # 2. discrete-time Fourier transform (DTFT) of a discrete harmonic exponential signal, and # 3. DTFT of a finite-length discrete harmonic exponential signal # 4. sampling of the DTFT. # ### Fourier Transform of an Exponential Signal # # The harmonic exponential signal is defined as # # \begin{equation} # x(t) = \mathrm{e}^{\,\mathrm{j}\, \omega_0 \, t} # \end{equation} # # where $\omega_0 = 2 \pi f$ denotes the angular frequency of the signal. The Fourier transform of the exponential signal is # # \begin{equation} # X(\mathrm{j}\, \omega) = \int\limits_{-\infty}^{\infty} x(t) \,\mathrm{e}^{\,- \mathrm{j}\, \omega \,t} \mathrm{d}t = 2\pi \; \delta(\omega - \omega_0) # \end{equation} # # The spectrum consists of a single shifted Dirac impulse located at the angular frequency $\omega_0$ of the exponential signal. Hence the spectrum $X(\mathrm{j}\, \omega)$ consists of a clearly isolated and distinguishable event. In practice, it is not possible to compute the Fourier transform of a continuous signal by means of digital signal processing. # ### Discrete-Time Fourier Transform of a Discrete Exponential Signal # # Now lets consider sampled signals. The discrete exponential signal $x[k]$ is derived from its continuous counterpart $x(t)$ above by equidistant sampling $x[k] := x(k T)$ with the sampling interval $T$ # # \begin{equation} # x[k] = \mathrm{e}^{\,\mathrm{j}\, \Omega_0 \,k} # \end{equation} # # where $\Omega_0 = \omega_0 T$ denotes the normalized angular frequency. The DTFT is the Fourier transform of a sampled signal. For the exponential signal it is given as (see e.g. [reference card discrete signals and systems](../reference_cards/RC_discrete_signals_and_systems.pdf)) # # \begin{equation} # X(\mathrm{e}^{\,\mathrm{j}\, \Omega}) = \sum_{k = -\infty}^{\infty} x[k]\, \mathrm{e}^{\,-\mathrm{j}\, \Omega \,k} = 2\pi \sum_{n = -\infty}^{\infty} \delta((\Omega-\Omega_0) - 2\,\pi\,n) # \end{equation} # # The spectrum of the DTFT is $2\pi$-periodic due to sampling. As a consequence, the transform of the discrete exponential signal consists of a series Dirac impulses. For the region of interest $-\pi < \Omega \leq \pi$ the spectrum consists of a clearly isolated and distinguishable event, as for the continuous case. # # The DTFT cannot be realized in practice, since is requires the knowledge of the signal $x[k]$ for all time instants $k$. In general, a measured signal is only known within a finite time-interval. The DFT of a signal of finite length can be derived from the DTFT in two steps: # # 1. truncation (windowing) of the signal and # 2. sampling of the DTFT spectrum of the windowed signal. # # The consequences of these two steps are investigated in the following. # ### Discrete-Time Fourier Transform of a Truncated Discrete Exponential Signal # # In general, truncation of a signal $x[k]$ to a length of $N$ samples is modeled by multiplying the signal with a window function $w[k]$ of length $N$ # # \begin{equation} # x_N[k] = x[k] \cdot w[k] # \end{equation} # # where $x_N[k]$ denotes the truncated signal and $w[k] = 0$ for $\{k: k < 0 \wedge k \geq N \}$. The spectrum $X_N(\mathrm{e}^{\,\mathrm{j}\, \Omega})$ can be derived from the multiplication theorem of the DTFT as # # \begin{equation} # X_N(\mathrm{e}^{\,\mathrm{j}\, \Omega}) = \frac{1}{2 \pi} X(\mathrm{e}^{\,\mathrm{j}\, \Omega}) \circledast_{2 \pi} W(\mathrm{e}^{\,\mathrm{j}\, \Omega}) # \end{equation} # # where $\circledast_{2 \pi}$ denotes a cyclic/[circular convolution](https://en.wikipedia.org/wiki/Circular_convolution) of period $2 \pi$. A hard truncation of the signal to $N$ samples is modeled by the rectangular signal # # \begin{equation} # w[k] = \text{rect}_N[k] = \begin{cases} # 1 & \mathrm{for} \; 0\leq k