Bohrium
robot
新建

空间站广场

论文
Notebooks
比赛
课程
Apps
我的主页
我的Notebooks
我的论文库
我的足迹

我的工作空间

任务
节点
文件
数据集
镜像
项目
数据库
公开
Digital-Signal-Processing_04_Random Signals and LTI-Systems_Power Spectral Densitity
English
notebook
Signal Processing
EnglishnotebookSignal Processing
喇叭花
发布于 2023-08-02
推荐镜像 :digital-signal-processing:Digital-Signal-Processing-Lecture
推荐机型 :c2_m4_cpu
Random Signals and LTI-Systems
Power Spectral Densitity
Example - Pink Noise
Cross-Power Spectral Densities
System Identification by Spectral Division
Example

Random Signals and LTI-Systems

🏃🏻 Getting Started Guide
This document can be executed directly on the Bohrium Notebook. To begin, click the Connect button located at the top of the interface, then select the digital-signal-processing:Digital-Signal-Processing-Lecture Image and choose your desired machine configuration to proceed.

📖 Source
This Notebook is from a famous Signal Processing Lecture. The notebooks constitute the lecture notes to the masters course Digital Signal Processing read by Sascha Spors, Institute of Communications Engineering, Universität Rostock.

This jupyter notebook is part of a collection of notebooks on various topics of Digital Signal Processing. Please direct questions and suggestions to Sascha.Spors@uni-rostock.de.

代码
文本

Power Spectral Densitity

For a wide-sense stationary (WSS) real-valued random process , the power spectral density (PSD) is given as the discrete-time Fourier transformation (DTFT) of the auto-correlation function (ACF)

Under the assumption of a real-valued LTI system with impulse response , the PSD of the output signal of an LTI system is derived by taking the DTFT of the ACF of the output signal

The PSD of the output signal of an LTI system is given by the PSD of the input signal multiplied with the squared magnitude of the transfer function of the system.

代码
文本

Example - Pink Noise

It can be concluded from above findings, that filtering can be applied to a white noise random signal with in order to create a random signal with a desired PSD

where denotes the power per frequency of the white noise. Such a random signal is commonly termed as colored noise. Different application specific types of colored noise exist. One of these is pink noise whose PSD is inversely proportional to the frequency. The approximation of a pink noise signal by filtering is illustrated by the following example. The PSDs and are estimated from and using the Welch technique.

代码
文本
[1]
import numpy as np
import matplotlib.pyplot as plt
import scipy.signal as sig

fs = 44100
N = 5*fs

# generate uniformly distributed white noise
np.random.seed(1)
x = np.random.uniform(size=N) - .5
# filter white noise to yield pink noise
# see http://www.firstpr.com.au/dsp/pink-noise/#Filtering
a = np.poly([0.99572754, 0.94790649, 0.53567505]) # denominator coefficients
b = np.poly([0.98443604, 0.83392334, 0.07568359]) # numerator coefficients
y = 1/3 * sig.lfilter(b, a, x)
# estimate PSDs using Welch's technique
f, Pxx = sig.csd(x, x, nperseg=256)
f, Pyy = sig.csd(y, y, nperseg=256)

# PSDs
Om = f * 2 * np.pi
plt.plot(Om, 20*np.log10(np.abs(.5*Pxx)),
label=r'$| \Phi_{xx}(e^{j \Omega}) |$ in dB')
plt.plot(Om, 20*np.log10(np.abs(.5*Pyy)),
label=r'$| \Phi_{yy}(e^{j \Omega}) |$ in dB')
plt.title('Power Spectral Density')
plt.xlabel(r'$\Omega$')
plt.legend()
plt.axis([0, np.pi, -60, -10])
plt.grid()
代码
文本

Let's listen to white and pink noise

代码
文本
[2]
from scipy.io import wavfile

wavfile.write('uniform_white_noise.wav', fs, np.int16(x*32768))
wavfile.write('uniform_pink_noise.wav', fs, np.int16(y*32768))
代码
文本

White noise

/uniform_white_noise.wav

Pink noise

/uniform_pink_noise.wav

代码
文本

Cross-Power Spectral Densities

The cross-power spectral densities and between the in- and output of an LTI system are given by taking the DTFT of the cross-correlation functions (CCF) and . Hence,

and

代码
文本

System Identification by Spectral Division

Using the result above for the cross-power spectral density between out- and input, and the relation of the CCF of finite-length signals to the convolution yields

holding for and . Hence, the transfer function of an unknown system can be derived by dividing the spectrum of the output signal through the spectrum of the input signal . This is equal to the definition of the transfer function. However, care has to be taken that the spectrum of the input signal does not contain zeros.

Above relation can be realized by the discrete Fourier transformation (DFT) by taking into account that a multiplication of two spectra results in the cyclic/periodic convolution . Since we aim at a linear convolution, zero-padding of the in- and output signal has to be applied.

代码
文本

Example

We consider the estimation of the impulse response of an unknown system using the spectral division method. Normal distributed white noise with variance is used as wide-sense ergodic input signal . In order to show the effect of sensor noise, normally distributed white noise with the variance is added to the output signal .

代码
文本
[3]
N = 1000 # number of samples for input signal

# generate input signal
# normally distributed (zero-mean, unit-variance) white noise
np.random.seed(1)
x = np.random.normal(size=N, scale=1)
# impulse response of the system
h = np.concatenate((np.zeros(20), np.ones(10), np.zeros(20)))
# output signal by convolution
y = np.convolve(h, x, mode='full')
# add noise to the output signal
y = y + np.random.normal(size=y.shape, scale=.1)

# zero-padding of input signal
x = np.concatenate((x, np.zeros(len(h)-1)))
# estimate transfer function
H = np.fft.rfft(y)/np.fft.rfft(x)
# compute inpulse response
he = np.fft.irfft(H)
he = he[0:len(h)]

# plot impulse response
plt.figure()
plt.stem(he, label='estimated')
plt.plot(h, 'g-', label='true')
plt.title('Estimated impulse response')
plt.xlabel(r'$k$')
plt.ylabel(r'$\hat{h}[k]$')
plt.legend();
代码
文本

Exercise

  • Change the length N of the input signal. What happens?
  • Change the variance of the additive noise. What happens?

Solution: Increasing the length N of the input signal lowers the uncertainty in estimating the impulse response. The higher the variance of the additive white noise, the higher the uncertainties in the estimated impulse response.

代码
文本

Copyright

This notebook is provided as Open Educational Resource. Feel free to use the notebook for your own purposes. The text is licensed under Creative Commons Attribution 4.0, the code of the IPython examples under the MIT license. Please attribute the work as follows: Sascha Spors, Digital Signal Processing - Lecture notes featuring computational examples.

代码
文本
English
notebook
Signal Processing
EnglishnotebookSignal Processing
点个赞吧
推荐阅读
公开
Digital-Signal-Processing 04Random Signals and LTI-Systems_Measurement of Acoustic Impulse Responses
EnglishnotebookSignal Processing
EnglishnotebookSignal Processing
喇叭花
发布于 2023-08-02
公开
Digital-Signal-Processing_04_Random Signals and LTI-Systems_Auto-Correlation Function
EnglishnotebookSignal Processing
EnglishnotebookSignal Processing
喇叭花
发布于 2023-08-02