位置:51电子网 » 技术资料 » D S P

用8位微处理器实现数字低通滤波器设计

发布时间:2008/5/27 0:00:00 访问次数:900

  一个简单的汇编程序适合于微处理器实现数字低通滤波器。
  滤波常发生在模拟世界。不幸的是,在数字领域,工程师通常主要使用dsp(数字信号处理器),而不是8位单片机实现滤波。这个情形的发生,是因为滤波器设计的算法比大多数工程师乐于处理的算法更复杂。而且,数字滤波需要计算整形数,而不是浮点数。这引发了两个问题。第一,有限位的舍入误差降低了滤波器响应,甚至使它不稳定。第二,必须用整数算法处理小数值。

  有几种方法解决这些问题。例如,可以使用16、32和64位数的操作,或可以缩放到更好的精度。这些和其他方法通常需要更多的存储器,造成编程经常不适于小型微处理器。文献研究所示用c语言编写的数字滤波固件,与用汇编语言编写需要更多的存储器。这个情形对存储器资源有限的小型微处理器来讲,常常是不可接受的。

  列表1(程序见英文原文)列出了一个用8位微处理器设计单极低通数字滤波器固件的简单方法。freescale公司的低端mc68hc908qt2使用汇编编程器,但可以将本设计方案用于任一型号微处理器,只要其使用的也是标准汇编指令。

  将基于广义z
  变换算法的复杂设计方案放在一边,本方案使用了一种基于递归方程的解决办法。计算每个输出信号采样,作为输入信号和前一个输出信号带相关系数的总和。递归方程定义一个单极低通滤波器为:y[n]=x[n]×a0+y[n–1]×b1,在这里x[n]和y[n]为采样[n]的输入输出值,y[n–1]为前一采样[n–1]的输出值,a0和b1为减少δ控制的权重系数。系数为0<δ<1的值,a0=1–δ且b1=δ。理论上,δ为输入信号从高电平降到低电平时,邻近的输出采样之间的衰减量。可以直接指定δ值或找到滤波器所需的时间常数d,其为采样数上升到低通滤波器稳态63.2%时的输出。d和δ之间存在确定的关系:δ=e–1/d,在这里e为自然对数基底。前面的公式服从y[n]=y[n–1]+(1–δ)×(x[n]–y[n–1])。

  为取代小数相乘,1–δ对汇编程序而言,用除以倒数为整数的方法更方便,f=1/(1–δ): y[n]=y[n–1]+(x[n]–y[n–1])/f。因此,可以按照下面的步骤确定数字滤波器参数:

  1、选择参数f。对汇编程序而言,便于用右移实现除法运算。右移就是f值应该为2s,在此s为偏移数。让f为8,相当于右移三位。

  2、计算衰减:δ=1–1/f=1–1/8=0.875。

  3、计算时间常数d=–1/lnδ=–1/ln0.875=7.49采样。

  公式y[n]=y[n–1]+(x[n]–y[n–1])/f决定滤波器的微处理器算法设计。算法需要三个寄存器:输入x[n]、输出y[n]和一个递增寄存器保存(x[n]–y[n–1])/f的值。三个寄存器的大小取决于输入。应用中,内置的8位adc输出范围从00到$ff的信号,必须经历低通滤波器。所以输入和输出寄存器均为1个字节。为增加除法精度,增加一半除数到被除数。这个处理将递增寄存器增加到2个字节。
  
  用数字方法实现滤波功能提供了一致性的好处,因为器件误差、温度漂移和老化不会影响滤波器算法。用微处理器实现数字滤波器,增加了可调整滤波器参数的灵活性优势,因为这个灵活性仅取决于固件。

  英文原文:

  8-bit microcontroller implements digital lowpass filter

  a simple assembler routine fits a digital lowpass filter into a microcontroller.

  abel raynus, armatron international, malden, ma; edited by charles h small and fran granville -- edn, 1/24/2008

  filtering occurs frequently in the analog world. unfortunately, in the digital world, engineers apply it mainly to the dsps (digital-signal processors) and not to the small 8-bit microcontrollers that designers commonly use. this situation occurs because the math for the filter design is more complicated than most engineers are willing to deal with. moreover, digital filtering requires calculations on integers instead of on floating-point numbers. this scenario causes two problems. first, the rounding-off error from the limited number of bits can degrade the filter response or even make it unstable. second, you must handle the fractional values with integer math.

  several ways exist to solve these issues. for example, you can use operations with 16-, 32-, and 64-bit numbers, or you can scale for better accuracy. these and other methods usually require more memory, and, as a result, the program often does not fit into a small microcontroller. a literature search shows that published digital-filter firmware is written in c. programs in c need more memory than those written in assembler. this situation often makes them

  一个简单的汇编程序适合于微处理器实现数字低通滤波器。
  滤波常发生在模拟世界。不幸的是,在数字领域,工程师通常主要使用dsp(数字信号处理器),而不是8位单片机实现滤波。这个情形的发生,是因为滤波器设计的算法比大多数工程师乐于处理的算法更复杂。而且,数字滤波需要计算整形数,而不是浮点数。这引发了两个问题。第一,有限位的舍入误差降低了滤波器响应,甚至使它不稳定。第二,必须用整数算法处理小数值。

  有几种方法解决这些问题。例如,可以使用16、32和64位数的操作,或可以缩放到更好的精度。这些和其他方法通常需要更多的存储器,造成编程经常不适于小型微处理器。文献研究所示用c语言编写的数字滤波固件,与用汇编语言编写需要更多的存储器。这个情形对存储器资源有限的小型微处理器来讲,常常是不可接受的。

  列表1(程序见英文原文)列出了一个用8位微处理器设计单极低通数字滤波器固件的简单方法。freescale公司的低端mc68hc908qt2使用汇编编程器,但可以将本设计方案用于任一型号微处理器,只要其使用的也是标准汇编指令。

  将基于广义z
  变换算法的复杂设计方案放在一边,本方案使用了一种基于递归方程的解决办法。计算每个输出信号采样,作为输入信号和前一个输出信号带相关系数的总和。递归方程定义一个单极低通滤波器为:y[n]=x[n]×a0+y[n–1]×b1,在这里x[n]和y[n]为采样[n]的输入输出值,y[n–1]为前一采样[n–1]的输出值,a0和b1为减少δ控制的权重系数。系数为0<δ<1的值,a0=1–δ且b1=δ。理论上,δ为输入信号从高电平降到低电平时,邻近的输出采样之间的衰减量。可以直接指定δ值或找到滤波器所需的时间常数d,其为采样数上升到低通滤波器稳态63.2%时的输出。d和δ之间存在确定的关系:δ=e–1/d,在这里e为自然对数基底。前面的公式服从y[n]=y[n–1]+(1–δ)×(x[n]–y[n–1])。

  为取代小数相乘,1–δ对汇编程序而言,用除以倒数为整数的方法更方便,f=1/(1–δ): y[n]=y[n–1]+(x[n]–y[n–1])/f。因此,可以按照下面的步骤确定数字滤波器参数:

  1、选择参数f。对汇编程序而言,便于用右移实现除法运算。右移就是f值应该为2s,在此s为偏移数。让f为8,相当于右移三位。

  2、计算衰减:δ=1–1/f=1–1/8=0.875。

  3、计算时间常数d=–1/lnδ=–1/ln0.875=7.49采样。

  公式y[n]=y[n–1]+(x[n]–y[n–1])/f决定滤波器的微处理器算法设计。算法需要三个寄存器:输入x[n]、输出y[n]和一个递增寄存器保存(x[n]–y[n–1])/f的值。三个寄存器的大小取决于输入。应用中,内置的8位adc输出范围从00到$ff的信号,必须经历低通滤波器。所以输入和输出寄存器均为1个字节。为增加除法精度,增加一半除数到被除数。这个处理将递增寄存器增加到2个字节。
  
  用数字方法实现滤波功能提供了一致性的好处,因为器件误差、温度漂移和老化不会影响滤波器算法。用微处理器实现数字滤波器,增加了可调整滤波器参数的灵活性优势,因为这个灵活性仅取决于固件。

  英文原文:

  8-bit microcontroller implements digital lowpass filter

  a simple assembler routine fits a digital lowpass filter into a microcontroller.

  abel raynus, armatron international, malden, ma; edited by charles h small and fran granville -- edn, 1/24/2008

  filtering occurs frequently in the analog world. unfortunately, in the digital world, engineers apply it mainly to the dsps (digital-signal processors) and not to the small 8-bit microcontrollers that designers commonly use. this situation occurs because the math for the filter design is more complicated than most engineers are willing to deal with. moreover, digital filtering requires calculations on integers instead of on floating-point numbers. this scenario causes two problems. first, the rounding-off error from the limited number of bits can degrade the filter response or even make it unstable. second, you must handle the fractional values with integer math.

  several ways exist to solve these issues. for example, you can use operations with 16-, 32-, and 64-bit numbers, or you can scale for better accuracy. these and other methods usually require more memory, and, as a result, the program often does not fit into a small microcontroller. a literature search shows that published digital-filter firmware is written in c. programs in c need more memory than those written in assembler. this situation often makes them

相关IC型号

热门点击

 

推荐技术资料

业余条件下PCM2702
    PGM2702采用SSOP28封装,引脚小而密,EP3... [详细]
版权所有:51dzw.COM
深圳服务热线:13751165337  13692101218
粤ICP备09112631号-6(miitbeian.gov.cn)
公网安备44030402000607
深圳市碧威特网络技术有限公司
付款方式


 复制成功!