get-the-solution

Signal sampling

By
on Regards: education; Article; python; sip;

Sampling

This text is from the category SIP (Signal and image processing). See also Signal Processing introduction

Sampling frequency

When working with signals, for computers its more convenient and efficient to work with discrete values. This requires an ability to convert signals from the the continuous time domain to the discrete time domain and visa versa. As the continues time domain is infinitely, the “sampling technique” provides an ability to make some kind of snapshots of the continuous time signal. The number of occurrences of a repeating event per unit of time[3] is the so called frequency.

Definitions of sampling frequency (fs):

SI Unit of frequency: Hz [s−1]

$f_s = \frac{AmountOfEvents}{unitOfTime}$

Ts = distance between samples

$f = \frac{1}{T}$

Note: Sampling frequency is the frequency of taking samples and differs from the signal frequencies.

Example 1:

Fig. 1. sampling frequency sample

Notice: Event number 5. is not considered as it belongs to the next “snapshot”.

$f_s = \frac{4}{1s}=4Hz$

$T_s = \frac{1}{4s}$

$f = \frac{1}{\frac{1}{4}s}$=4Hz

Windowing

Window Design

We have given an infinity long signal and we only observed it in a finite “window”.

(Fig 2. signal and window function)

The observed signal can be retrieved by multiplying the window function with its original signal. The window function can be for instance rectangular one and is outside of the “window” zero.  = w[n] ⋅ x[n].

(Fig 3. frequency window function)

The spectrum of the rectangular window function will result in a sinc-function. Designing window functions result in a trade off. You can choose between stronger distortions for the locally frequencies and weaker distortions for those who are further away. Or you do it the other way around.

Note: You cannot avoid some distortions of your spectrum for the final signal length part. But you can choose by the window function how your spectrum gets distorted.

One of the most popular windows is the Hann window function.

Observing a signal for a final length distorts the spectrum and may it make difficult to properly resolve all the spectrums components of the signal. Shorter the signal is the more severe the distortions.

Sampling signal

Sampling is the process from “converting” a signal from the continues time domain to a discrete time signal. Under certain conditions its possible to reconstruct the continues signal from the discrete signal.

fs...samplingfrequency

(Fig 4. sampling)

With the function S(t) we generate spikes at a fixed time interval in the continues time domain (dirac impulse)

$S(t)=\sum_{\infty}^{n=-\infty} \delta(t-nTs); f_s=1/T_s$

Calculate the discrete time signal Xs(t) by:

$X_s(t)=X(t)*S(t)=\sum_{\infty}^{n=-\infty} x[n]\cdot \delta(t-nTs)$

x[n]…where we want to sample

Ω…frequency in the continues Time domain (physical units in Hz)

ω…discrete time series frequency

Calculate the spectrum of Xs(Ω)

$X_s(\Omega)=\frac{1}{T_s}\sum_{k=-\infty}^{\infty} \overbrace{X(\Omega-k\cdot\Omega_s)}^{\text{signal gets shifted by }\Omega_s~k-times} \qquad \Omega_s=2\cdot\pi\cdot f_s$

Xs(Ω) is an infinite signal which gets shifted by Ωs

$S(\Omega)=\frac{2\cdot\pi}{T_s}\sum_{k=-\infty}^{\infty}\delta(\Omega-k\cdot\Omega_s)$

From the modulation theorem we know that the spectrum of our sample signal is given by our original signal convolved with our sampling function:

Xs(Ω) = X(Ω) * S(Ω)

The spectrum of Xs(t) is shifted infinite k-times.

Nyquist–Shannon sampling theorem

Let X(t) be a bandlimited signal with X(Ω) = 0for|Ω| ≥ ΩN. Then x(t) is uniquely determined by its samples x[n]=(nTs) if the sampling frequency Ωs ≥ 2ΩN

For example: Audio files. Human is able to hear or recognize noises with a frequency up to 22kHz. For this reason the signal needs to be sampled with a sampling frequency of 44kHz.

Relation of Ω and ω

Ω ⋅ T ⋅ s = ω

$f=\frac{\omega\cdot f_s}{2\cdot\pi}$

Sample:

Lets assume we have a discrete time signal X(ω) with a spectrum from π to π Now we want to know, to which physical frequencies X(ω) is corresponding?

$f_{\omega=\pi}=\frac{\pi\cdot f_s}{2\cdot\pi}=\frac{f_s}{2}$

$f_{\omega=-\pi}=-\frac{f_s}{2}$

This means if we for example sample a signal at 1kHz and compute the DFT and plot the spectrum from π to π over the frequencies from -500Hz to + 500Hz.

Relation of the sampling frequency, window length and the frequency resolution

-> Sampling frequency has no impact to the frequency resolution.

Frequency resolution is determined by its window length

N… length of signal

$frequency-resolution-(physical)=\frac{f_s}{N}=\frac{f_s}{T\cdot f_s}=\frac{1}{T}$

For example: Record an audio signal for one 1s. Then the DFT gives gives us a frequency of 1Hz. Record 10s frequency resolution is 0.1Hz. This means we need a certain frequency resolution to resolve oscillations on which we are interested in. If the recording window is too short than the frequency resolution is maybe to coarse grain to see whats actual going on.

We can choose between:

  • Get accurate signal by time but frequency resolution is maybe inaccurate
  • Get precise frequency but we can’t determine certainly where frequency occurs in signal

Resampling

Change the sampling rate after the signal was recorded. For example we want to do that to save storage on the computer.

Downsampling

Naive down sampling: by a factor of two we set every second sample to 0 (drop every second sample). Extended down sampling: To downsample by an integer factor u, we first have to apply a lowpass-filter at cut off frequencies $+-\frac{\pi}{u}$, and then compute the new signal xd[n] = xLowPass[u ⋅ n]

Note: That you have to adjust your sampled frequency after the downsampling. For example drop every second sample -> fsdown = fs/2

Upsampling

For example upsampling signal x[n] by a factor L=2 to the new signal xu[n]. We need to reconstruct every second signal. We can do that for example with a linear interpolation, which is not a good practice.

Better do the resampling with:

$x_u[n]=\sum^{\infty}_{k=-\infty}x[k]\cdot\delta[n-k\cdot L]$

$X_u(\omega)=\sum^{\infty}_{k=-\infty}x[n]\cdot e^{-j\omega\cdot L\cdot k}=X(\omega L)$

Upsampling by creating a new upsampled signal $x_u[n]=\sum^{\infty}_{k=-\infty}x[k]\cdot\delta[n-k\cdot L]$ and than apply low pass filter with cut off frequency $\frac{+\pi}{-L}$.

General Resampling $\frac{L}{u}$: First upsample by L, then downsample by u.

That you have to adjust your sampled frequency after the upsampling. For example extend sample by a factor of two -> fsup = fs * 2

In principal we can resample at any frequency we like. However there is one small thing to take in consideration. It could be that to resample by one specific fraction we first have to upsample by a very large number L before downlsampling again by a very large number m and this upsampling takes an extra ordinary amount of memory. If not careful enough you we can run into computation problems.

Continue to signal filtering

Sources: