第16章(Chapter 16)
数字型号处理(Digital Signal Processing)
介绍(Introduction)
The development of programmable digital logic and microprocessors and the availability of fast, reliable memory has made digital signal processing an attractive option in many applications that have hitherto depended on analogue techniques as well as opening up new possibilities that have not previously been viable.
可编程数字逻辑和微处理器的发展以及快速,可靠的存储器的可用性,使得数字信号处理在迄今为止依赖于模拟技术的许多应用中成为一种有吸引力的选择,并且开辟了以前不可行的新可能性。
Functions such as filtering, peak detection and frequency analysis can be performed numerically, often at lower financial cost – as well as in terms of board area, component count and set-up time – than for their analogue equivalents. Digital devices are essentially drift-free and calibration and alignment functions can be implemented in software very easily.
过滤,峰值检测和频率分析等功能可以通过数字方式执行,通常其财务成本(以及电路板面积,组件数量和设置时间)要比其模拟等效产品低。数字设备本质上是无漂移的,并且校准和对准功能可以很容易地在软件中实现。
Digital signal processing solutions also offer the potential for in-the-field re-configuration or even self-adapting which can enhance maintenance and reduce the cost of ownership of products.
数字信号处理解决方案还提供了现场重新配置甚至自适应的潜力,这可以增强维护并降低产品拥有成本。
This chapter does not cover the detail of mathematics required to analyse and design digital filter and signal processing implementations or algorithms but is intended to convey the key points and implementation compromises that apply to digital signal processing using microcontrollers and DSP engines.
本章不涵盖分析和设计数字滤波器和信号处理实现或算法所需的数学细节,而是旨在传达适用于使用微控制器和DSP引擎进行数字信号处理的关键点和实现折衷方案。
低通和高通滤波器(Low-pass and high-pass filters)
Analogue filters are usually linear time invariant systems and are characterized by the fact that they obey the principle of superposition, that is the output resulting from applying the sum of a set of independent signals to the input of a filter is the same as summing the outputs obtained for all the signals applied independently. This being the case, we can characterize a filter by its step response – the output response to an infinitely fast rise time step at the input.
模拟滤波器通常是线性时不变系统,并且其特征在于它们服从叠加原理,即从应用一组独立的信号到滤波器的输入的总和而产生的输出的事实是一样的输出求和 对于独立施加的所有信号获得。 在这种情况下,我们可以通过阶跃响应来表征滤波器-输出对输入端无限快的上升阶跃的输出响应。
低通滤波器(Low-Pass Filter)
Figure 16.1 Step input signal (a), RC low-pass filter (b), output response ©, sampled input (d) and output (e) signals.
Figure 16.1 shows the response of a simple RC network, a low-pass filter, to a unit step at its input. We saw earlier in Chapter 2 that the output can be considered to have settled to the final value after approximately 5 time constants of the RC network.
图16.1示出了简单的RC网络,一个低通滤波器的响应,以在其输入端的单位工序。 我们在第2章前面看到,输出可以被认为是后RC网络约5时间常数已经解决到最终值。
If we sample the input and output signals with an ADC the sampled data might look as shown in Figure 16.1. As one would expect of a low-pass filter, the output signal does not follow the input instantly but grows towards the final value over time. A low-pass filter is in fact averaging the input with respect to time. If we were to average the converted data with a moving average function over 5 samples, for example:
如果我们使用ADC对输入和输出信号进行采样,则采样数据可能如图16.1所示。 就像人们对低通滤波器的期望一样,输出信号不会立即跟随输入,而是会随着时间的推移逐渐趋向最终值。 实际上,低通滤波器是相对于时间平均输入。 如果我们使用5个样本的移动平均函数对转换后的数据进行平均,例如:
n Yn = 1/5 ∑ Xn n-4
the output y at time n is equal to the sum for the last 5 input samples x n … x n−4 divided by 5. The input and output data are represented in Table 16.1. The moving average grows linearly in response to a step input and although useful in some circumstances does not match the RC low-pass filter very well.
在时间n处的输出y等于最后5个输入采样的总和 设 Xn … x n-4除以5。表16.1表示输入和输出数据。 移动平均值响应于阶跃输入而线性增长,尽管在某些情况下有用,但它与RC低通滤波器的匹配非常不理想。
Table 16.1 Simple low-pass filtering by averaging
Input step | Moving average | Binary weighted series | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.2 | 0.5 | 1 | 0.4 | 0.75 | 1 | 0.6 | 0.875 | 1 | 0.8 | 0.9375 | 1 | 1 | 0.96875 | 1 | 1 | 0.984375 | 1 | 1 | 0.984375 | 1 | 1 | 0.984375 | 1 | 1 | 0.984375 | 1 | 1 | 0.984375 |
A better approximation to the RC low-pass filter characteristic is a binary weighted sequence. As shown in the table this grows more slowly as it gets nearer the final value, (Figure 16.2) just like a real RC low-pass filter output. The binary weighted series used here is:
RC低通滤波器特性的更好近似是二进制加权序列。 如表中所示,该值随着接近最终值(图16.2)而增长得更慢,就像实际的RC低通滤波器输出一样。 这里使用的二进制加权序列是:
Yn = 1/2*Xn + 1/4*Xn-1 + 1/8*Xn-2 + 1/16*Xn-3 + 1/32*Xn-4
which is easy to implement in a simple microcontroller because the only operations required are shifts and adds; in fact this can be quite efficiently implemented because each coefficient is the previous one shifted once to the right.
这是很容易在简单的微控制器中实现的,因为所需的唯一操作是移位和加法; 实际上,由于每个系数都是前一个向右偏移的系数,因此可以非常有效地实现。
The time constant of the filter depends on the number of terms in the filter function as well as the sampling rate.
滤波器的时间常数取决于滤波器功能中的项数以及采样率。
高通滤波器(High-Pass Filter)
High-pass filters can be implemented in the same way. A high-pass filter is effectively a change or edge detector; the output is zero unless the input is changing at a frequency above the cut-off frequency (Figure 16.3).
高通滤波器可以用相同的方法实现。高通滤波器实际上是一个变化或边缘检测器。除非输入以高于截止频率的频率变化,否则输出为零(图16.3)。
Considering a series of samples at regular time intervals an edge detection function needs to determine whether the current sample is different from the one that preceded it, so simply subtracting the last sample from the current one would detect a change.
考虑到以规则的时间间隔进行的一系列采样,边缘检测功能需要确定当前采样是否不同于之前的采样,因此只需从当前采样中减去最后一个采样即可检测到变化。
Yn = Xn - Xn-1
This basic edge detector can be made more like a real RC high-pass filter by using a binary weighted sequence to control the rate of decay of the step response, in the same way that it controlled the rate at which the low-pass filter converged on a steady value. In this case the filter needs to respond to rapid changes immediately and recover exponentially from the effect.
通过使用二进制加权序列来控制阶跃响应的衰减速率,可以像控制低通滤波器收敛的速率一样,使该基本边缘检测器更像真实的RC高通滤波器。保持稳定的价值。在这种情况下,滤镜需要立即响应快速变化,并从效果中呈指数恢复。
Yn = Xn - 1/2*Xn-1 - 1/4*Xn-2 - 1/8*Xn-3 - 1/16*Xn-4 - 1/32*Xn-5 - 1/64*Xn-6
Again this binary weighting of the sequence is very easy to implement in a microcontroller. Sampling rate and the values of the coefficients determine the cut-off frequency of the filter. Figure 16.3 shows the step response and
同样,该序列的二进制加权非常容易在微控制器中实现。采样率和系数值决定了滤波器的截止频率。图16.3显示了阶跃响应和
Table 16.2 the input and output values.
Because this high-pass filter implementation is asymmetric, truncation of the series results in an offset at the output equal to the last term of the series. A way round this can be to double the value of the last coefficient as shown.
由于此高通滤波器的实现是不对称的,因此序列的截断会导致输出的偏移等于该序列的最后一项。如图所示,可以将最后一个系数的值加倍。
Yn = Xn - 1/2*Xn-1 - 1/4*Xn-2 - 1/8*Xn-3 - 1/16*Xn-4 - 1/32*Xn-5 - 1/64*Xn-6
Truncation always introduces an error. The size of this error and the best way of dealing with it depends on the length of the series, the application and cost in processor clock cycles and memory of using a longer series or a different filter implementation. Frequency domain effects of truncation will be covered later in this chapter.
截断总是引入错误。此错误的大小和最佳处理方式取决于序列的长度,处理器时钟周期的应用和成本以及使用较长序列或其他滤波器实现的内存。截断的频域效应将在本章后面介绍。
Simple low-pass and high-pass filter functions like the ones described can be very useful for rejecting mains frequency noise in microcontroller applications.
简单的低通和高通滤波器功能,如所述 对于抑制微控制器应用中的电源频率噪声非常有用。