Bohrium
robot
新建

空间站广场

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

我的工作空间

任务
节点
文件
数据集
镜像
项目
数据库
公开
DSP_09_Design of Digital Filters_Design of Non-Recursive Filters using the Window Method
English
notebook
Signal Processing
EnglishnotebookSignal Processing
喇叭花
发布于 2023-08-02
推荐镜像 :digital-signal-processing:Digital-Signal-Processing-Lecture
推荐机型 :c2_m4_cpu
Design of Digital Filters
Design of Non-Recursive Filters using the Window Method
Causal Filters
Example - Causal approximation of ideal low-pass
Zero-Phase Filters
Causal Linear-Phase Filters
Example - Causal linear-phase approximation of ideal low-pass

Design of Digital Filters

🏃🏻 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.

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.

代码
文本

Design of Non-Recursive Filters using the Window Method

The design of non-recursive filters with a finite-length impulse response (FIR) is a frequent task in practical applications. The designed filter should approximate a prescribed frequency response as close as possible. First, the design of causal filters is considered. For many applications the resulting filter should have a linear phase characteristic since this results in a constant (frequency independent) group delay. We therefore specialize the design to causal linear-phase filters in a second step.

代码
文本

Causal Filters

Let's assume that the desired frequency characteristic of the discrete filter is given by its continuous frequency response in the discrete-time Fourier domain. Its impulse response is given by inverse discrete-time Fourier transform (inverse DTFT) of the frequency response

In the general case, will not be a causal FIR. The Paley-Wiener theorem states, that the transfer function of a causal system may only have zeros at a countable number of single frequencies. This is not the case for idealized filters, like e.g. the ideal low-pass filter, were the transfer function is zeros over an interval of frequencies. The basic idea of the window method is to truncate the impulse response in order to derive a causal FIR filter. This can be achieved by applying a window of finite length to

where denotes the impulse response of the designed filter and for . Its frequency response is given by the multiplication theorem of the discrete-time Fourier transform (DTFT)

where denotes the DTFT of the window function . The frequency response of the filter is given as the periodic convolution of the desired frequency response and the frequency response of the window function . The frequency response is equal to the desired frequency response only if . This would require that for . Hence for a window of finite length, deviations from the desired frequency response are to be expected.

In order to investigate the effect of truncation on the frequency response , a particular window is considered. A straightforward choice is the rectangular window of length . Its DTFT is given as

The frequency-domain properties of the rectangular window have already been discussed for the leakage effect. The rectangular window features a narrow main lobe at the cost of relative high sidelobe level. The main lobe gets narrower with increasing length . The convolution of the desired frequency response with the frequency response of the window function effectively results in smoothing and ringing. While the main lobe will smooth discontinuities of the desired transfer function, the sidelobes result in undesirable ringing effects. The latter can be alleviated by using other window functions. Note that typical window functions decay towards their ends and are symmetric with respect to their center. This may cause problems for desired impulse responses with large magnitudes towards their ends.

代码
文本

Example - Causal approximation of ideal low-pass

The design of an ideal low-pass filter using the window method is illustrated in the following. For the transfer function of the ideal low-pass is given as

where denotes the cut frequency of the low-pass. An inverse DTFT of the desired transfer function yields

The impulse response is not causal nor FIR. In order to derive a causal FIR approximation, a rectangular window of length is applied

The resulting magnitude and phase response is computed numerically in the following.

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

N = 32 # length of filter
Omc = np.pi/2

# compute impulse response
k = np.arange(N)
hd = Omc/np.pi * np.sinc(k*Omc/np.pi)
# windowing
w = np.ones(N)
h = hd * w

# frequency response
Om, H = sig.freqz(h)

# plot impulse response
plt.figure(figsize=(10, 3))
plt.stem(h, use_line_collection=True)
plt.title('Impulse response')
plt.xlabel(r'$k$')
plt.ylabel(r'$h[k]$')
# plot magnitude responses
plt.figure(figsize=(10, 3))
plt.plot([0, Omc, Omc], [0, 0, -100], 'r--', label='desired')
plt.plot(Om, 20 * np.log10(abs(H)), label='window method')
plt.title('Magnitude response')
plt.xlabel(r'$\Omega$')
plt.ylabel(r'$|H(e^{j \Omega})|$ in dB')
plt.axis([0, np.pi, -20, 3])
plt.grid()
plt.legend()
# plot phase responses
plt.figure(figsize=(10, 3))
plt.plot([0, Om[-1]], [0, 0], 'r--', label='desired')
plt.plot(Om, np.unwrap(np.angle(H)), label='window method')
plt.title('Phase')
plt.xlabel(r'$\Omega$')
plt.ylabel(r'$\varphi (\Omega)$ in rad')
plt.grid()
plt.legend()
/tmp/ipykernel_278/177196574.py:21: MatplotlibDeprecationWarning: The 'use_line_collection' parameter of stem() was deprecated in Matplotlib 3.6 and will be removed two minor releases later. If any parameter follows 'use_line_collection', they should be passed as keyword, not positionally.
  plt.stem(h, use_line_collection=True)
代码
文本

Exercises

  • Does the resulting filter have the desired phase?
  • Increase the length N of the filter. What changes?

Solution: The desired filter has zero-phase for all frequencies, hence . The phase of the resulting filter is not zero as can be concluded from the lower illustration. The small local variations (ripples) in the magnitude of the transfer function of the resulting filter decrease with an increasing number N of filter coefficients. The achievable attenuation in the stop-band of the low-pass does not change.

代码
文本

Zero-Phase Filters

Lets assume a general zero-phase filter with transfer function with magnitude . Due to the symmetry relations of the DTFT, its impulse response is conjugate complex symmetric

A zero-phase filter of length is not causal as a consequence. The anti-causal part could simply be removed by windowing with a heaviside signal. However, this will result in large deviations between the desired transfer function and the designed filter. This explains the findings from the previous example, that an ideal-low pass cannot be realized very well by the window method. The reason is that an ideal-low pass has zero-phase, as most of the idealized filters.

The impulse response of a stable system, in the sense of the bounded-input/bounded-output (BIBO) criterion, has to be absolutely summable. Which in general is given when its magnitude decays by tendency with increasing time-index . This observation motivates to shift the desired impulse response to the center of the window in order to limit the effect of windowing. This can be achieved by replacing the zero-phase with a linear-phase, as is illustrated below.

代码
文本

Causal Linear-Phase Filters

The design of a non-recursive causal FIR filter with a linear phase is often desired due to its constant group delay. Let's assume a filter with generalized linear phase. For its transfer function is given as

where denotes the amplitude of the filter, the linear slope of the phase and a constant phase offset. Such a system can be decomposed into two cascaded systems: a zero-phase system with transfer function and an all-pass with phase . The linear phase term results in the constant group delay .

The impulse response of a linear-phase system shows a specific symmetry which can be deduced from the symmetry relations of the DTFT for odd/even symmetry of as

for where denotes the length of the (finite) impulse response. The transfer function of a linear phase filter is given by its DTFT

Introducing the symmetry relations of the impulse response into the DTFT and comparing the result with above definition of a generalized linear phase system reveals four different types of linear-phase systems. These can be discriminated with respect to their phase and magnitude characteristics

Type Length Impulse Response Group Delay in Samples Constant Phase Transfer Function
1 odd , all filter characteristics
2 even , , only lowpass or bandpass
3 odd , , only bandpass
4 even , , only highpass or bandpass

These relations have to be considered in the design of a causal linear phase filter. Depending on the desired magnitude characteristics the suitable type is chosen. The odd/even length of the filter and the phase (or group delay) is chosen accordingly for the design of the filter.

代码
文本

Example - Causal linear-phase approximation of ideal low-pass

We aim at the design of a causal linear-phase low-pass using the window technique. According to the previous example, the desired frequency response has an even symmetry with . This could be realized by a filter of type 1 or 2. We choose type 1 with , since the resulting filter exhibits an integer group delay of samples. Consequently the length of the filter has to be odd.

The impulse response is given by the inverse DTFT of incorporating the linear phase

The impulse response fulfills the desired symmetry for . A causal FIR approximation is obtained by applying a window function of length to the impulse response

Note that the window function also has to fulfill the desired symmetries.

As already outlined, the chosen window determines the properties of the transfer function . The spectral properties of commonly applied windows have been discussed previously. The width of the main lobe will generally influence the smoothing of the desired transfer function , while the sidelobes influence the typical ringing artifacts. This is illustrated in the following.

代码
文本
[2]
N = 33 # length of filter
Omc = np.pi/2

# compute impulse response
k = np.arange(N)
hd = Omc/np.pi * np.sinc((k-(N-1)/2)*Omc/np.pi)
# windowing
w1 = np.ones(N)
w2 = np.blackman(N)
h1 = hd * w1
h2 = hd * w2

# frequency responses
Om, H1 = sig.freqz(h1)
Om, H2 = sig.freqz(h2)

# plot impulse response
plt.figure(figsize=(10, 3))
plt.stem(h1, use_line_collection=True)
plt.title('Impulse response (rectangular window)')
plt.xlabel(r'$k$')
plt.ylabel(r'$h[k]$')
# plot magnitude responses
plt.figure(figsize=(10, 3))
plt.plot([0, Omc, Omc], [0, 0, -300], 'r--', label='desired')
plt.plot(Om, 20 * np.log10(abs(H1)), label='rectangular window')
plt.plot(Om, 20 * np.log10(abs(H2)), label='Blackmann window')
plt.title('Magnitude response')
plt.xlabel(r'$\Omega$')
plt.ylabel(r'$|H(e^{j \Omega})|$ in dB')
plt.axis([0, np.pi, -120, 3])
plt.legend(loc=3)
plt.grid()
# plot phase responses
plt.figure(figsize=(10, 3))
plt.plot(Om, np.unwrap(np.angle(H1)), label='rectangular window')
plt.plot(Om, np.unwrap(np.angle(H2)), label='Blackmann window')
plt.title('Phase')
plt.xlabel(r'$\Omega$')
plt.ylabel(r'$\varphi (\Omega)$ in rad')
plt.legend(loc=3)
plt.grid()
/tmp/ipykernel_278/1532763926.py:19: MatplotlibDeprecationWarning: The 'use_line_collection' parameter of stem() was deprecated in Matplotlib 3.6 and will be removed two minor releases later. If any parameter follows 'use_line_collection', they should be passed as keyword, not positionally.
  plt.stem(h1, use_line_collection=True)
代码
文本

Exercises

  • Does the impulse response fulfill the required symmetries for a type 1 filter?
  • Can you explain the differences between the magnitude responses for the different window functions?
  • What happens if you increase the length N of the filter?

Solution: Inspection of the impulse response reveals that it shows the symmetry of a type 1 filter for odd N. The rectangular window features a narrow main lobe at the cost of a high level of the side lobes, the main lobe of the Blackmann window is wider but the level of the side lobes is lower compared to the rectangular window. This explains the behavior of the magnitude responses in the stop-band of the realized low-passes. The distance between the local minima in the magnitude responses decreases with increasing length N and the attenuation for frequencies towards the Nyquist frequency increases.

代码
文本

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
点个赞吧
推荐阅读
公开
DSP_09_Design of Digital Filters_Example: Non-Recursive versus Recursive Filter
EnglishnotebookSignal Processing
EnglishnotebookSignal Processing
喇叭花
发布于 2023-08-02
公开
DSP_09_Design of Digital Filters_Design of Non-Recursive Filters using the Frequency Sampling Method
EnglishnotebookSignal Processing
EnglishnotebookSignal Processing
喇叭花
发布于 2023-08-02