源:http://blog.sina.com.cn/s/blog_493520900102uy26.html

内容来自于上篇博文,第七章,FIR滤波器

http://blog.sina.com.cn/s/blog_493520900102uxzu.html

 
使用 FDATool工具,构建一个Kaiser窗低通滤波器,采样频率8kHz,生成滤波器系数:
 
1)例程1
 
文件 fir_fltcoeff.h,以浮点形式表示的量化后的滤波器系数
//define the   FIR  filter  length
#define   N_FIR  40
 
float   h[N_FIR]  =  { ‐ 0.004314029307,‐ 0.013091321622,‐0.016515087727,
                  ‐0.006430584433,  0.009817876267, 0.010801880238,
                  ‐0.006567413713,‐ 0.016804829623, 0.000653253913,
                   0.022471280087,  0.010147131468,‐0.025657740989,
                  ‐0.026558960619,  0.023048392854, 0.050385290390,
                  ‐0.009291203588,‐ 0.087918503442,‐0.033770330014,
                   0.187334796517,  0.401505729848, 0.401505729848,
                   0.187334796517,‐ 0.033770330014,‐0.087918503442,
                  ‐0.009291203588,  0.050385290390, 0.023048392854,
                  ‐0.026558960619,‐ 0.025657740989, 0.010147131468,
                   0.022471280087,  0.000653253913,‐0.016804829623,
                  ‐0.006567413713,  0.010801880238, 0.009817876267,
                  ‐0.006430584433,‐ 0.016515087727,‐0.013091321622,
                  ‐0.004314029307   };
 
实际电路用AIC3106,每次采样中断来临后读入一组数据,分别为左右声道的数据,各16位。中断服务程序将左声道的每个数据送入滤波器,然后从DAC电路输出滤波后的结果。右声道数据不变。
 
文件 ISRs_Plus.c ,中断服务程序:
// Welch, Wright, & Morrow, 
// Real-time Digital Signal Processing, 2011
// Modified by Mark Wickert February 2012 to include GPIO ISR start/stop postings
 
///////////////////////////////////////////////////////////////////////
// Filename: ISRs_fir_float.c
//
// Synopsis: Interrupt service routine for codec data transmit/receive
//           floating point FIR filtering with coefficients in *.h file
//
///////////////////////////////////////////////////////////////////////
 
#include "DSP_Config.h"
#include "fir_fltcoeff.h"   //coefficients in float format
 
// Function Prototypes
long int rand_int(void);
  
// Data is received as 2 16-bit words (left/right) packed into one
// 32-bit word.  The union allows the data to be accessed as a single 
// entity when transferring to and from the serial port, but still be 
// able to manipulate the left and right channels independently.
 
#define LEFT  0
#define RIGHT 1
 
volatile union {
Uint32 UINT;
Int16 Channel[2];
} CodecDataIn, CodecDataOut;
 
 
float x_buffer[N_FIR];       //buffer for delay samples
 
 
interrupt void Codec_ISR()
///////////////////////////////////////////////////////////////////////
// Purpose:   Codec interface interrupt service routine  
//
// Input:     None
//
// Returns:   Nothing
//
// Calls:     CheckForOverrun, ReadCodecData, WriteCodecData
//
// Notes:     None
///////////////////////////////////////////////////////////////////////
{                    
WriteDigitalOutputs(1); // Write to GPIO J15, pin 6; begin ISR timing pulse
int i;
float result = 0; //initialize the accumulator
 
 
  if(CheckForOverrun()) // overrun error occurred (i.e. halted DSP)
return; // so serial port is reset to recover
 
  CodecDataIn.UINT = ReadCodecData(); // get input data samples
 
//Work with Left ADC sample
//x_buffer[0] = 0.25 * CodecDataIn.Channel[ LEFT];
//Use the next line to noise test the filter
x_buffer[0] = 0.125*((short) rand_int());//scale input by 1/8
 
//Filtering using a 32-bit accumulator
for(i=0; i< N_FIR; i++)
{
result += x_buffer[i] * h[i];
}
//Update filter history
for(i=N_FIR-1; i>0; i--)
{
x_buffer[i] = x_buffer[i-1];
}
 
//Return 16-bit sample to DAC
CodecDataOut.Channel[ LEFT] = (short) result;
// Copy Right input directly to Right output with no filtering
CodecDataOut.Channel[RIGHT] = CodecDataIn.Channel[ RIGHT];
WriteCodecData(CodecDataOut.UINT); // send output data to  port
WriteDigitalOutputs(0); // Write to GPIO J15, pin 6; end ISR timing pulse
}
 
//White noise generator for filter noise testing
long int rand_int(void)
{
static long int a = 100001;
 
a = (a*125) % 2796203;
return a;
}
 
可以看出,中断服务程序是逐点响应的,每次来一个数据,都要做一次滤波器运算,并将原有的数据前移一位,将新数据追加在缓冲区末尾。
float x_buffer[N_FIR]; // 用于保存现在的新值和过去的数值,长度与滤波器系数相同
x_buffer[0] // 用于保存当前值
x_buffer[1] // 保存过去前一点的值,以此类推
h[0...39] // 滤波器系数
result += x_buffer[i] * h[i]; // 当前点滤波器输出结果,循环从0到39

FIR滤波器的实现方法(转)的更多相关文章

  1. 转载论文关于fir滤波器的fpga实现

    摘 要 本文讨论的FIR滤波器因其具有严格的线性相位特性而得到广泛的应用.在工程实践中,往往要求信号处理具有实时性和灵活性,本论文研究FIR的FPGA解决方案正体现了电子系统的微型化和单片化. 本论文 ...

  2. FIR滤波器的FPGA实现方法

    FIR滤波器的FPGA实现方法 2011-02-21 23:34:15   来源:互联网    非常重要的基本单元.近年来,由于FPGA具有高速度.高集成度和高可靠性的特点而得到快速发展.随着现代数字 ...

  3. 数字信号处理实验(六)——FIR滤波器的设计

    一.四种线性相位FIR滤波器的振幅响应 1.自编函数 [Hr,w,a,L]=-n) [Hr,w,a,L]=-n) [Hr,w,a,L]=-n) [Hr,w,a,L]=-n) 2.一个demo clea ...

  4. FIR滤波器(1)- 基础知识

    FIR滤波器广泛应用于数字信号处理中,主要功能就是将不感兴趣的信号滤除,留下有用信号.FIR滤波器是全零点结构,系统永远稳定:并且具有线性相位的特征,在有效频率范围内所有信号相位上不失真.在无线通信收 ...

  5. FIR滤波器设计

    FIR滤波器的优越性: 相位对应为严格的线性,不存在延迟失真,仅仅有固定的时间延迟: 因为不存在稳定性问题,设计相对简单: 仅仅包括实数算法,不涉及复数算法,不须要递推运算,长度为M,阶数为M-1,计 ...

  6. FIR滤波器工作原理(算法)以及verilog算法实现(包含与IIR的一些对比)

    滤波器在2017年IC前端的笔试中,出现频率十分的高.不论今后是否会涉及,还是要记住一些会比较好.接下来就将从这四个方面来讲解,FIR数字滤波器的工作原理(算法)与verilog实现. ·什么是FIR ...

  7. matlab进行FIR滤波器设计(一)

    来源:https://blog.csdn.net/leokingszx/article/details/80041910 在实际的应用中,有时需要使用FIR根据完成一些特定功能,比如近似一阶RC低通电 ...

  8. IIR滤波器和FIR滤波器的区别与联系zz

      -------------------------------------------------------------------------------------------------- ...

  9. CIC and Fir 滤波器的级联

    在FDATool中 CIC 和 Fir 级联滤波器的设计 1 设计CIC滤波器的幅频特性曲线如下 2.设计FIR 滤波器的幅频特性曲线如下 3.总的特性曲线如下 4.把通带部分放大后的图,比较平坦

随机推荐

  1. Ubuntu 网管服务器配置

    1.设置Linux内核支持ip数据包的转发 echo "1" > /proc/sys/net/ipv4/ip_forward or vi /etc/sysctl.conf   ...

  2. PHP xdebug的安装

    xdebug实际上就是PHP的一个第三方扩展 安装xdebug步骤和添加一个PHP扩展一样 linux:去xdebug官网下载对应版本的源码,然后像编译其他linux扩展一样,详解我的一篇关于Linu ...

  3. 常见html标签

    1.flash嵌入标签 <object> <embed allowscriptaccess="always" allowfullscreen="true ...

  4. JS-加载页面的时候自动选择刚才所选择option

    <body class="no-skin" onload="option_auto(${pd.PACK_SORT})"> <select na ...

  5. 转 Oracle DBCA高级玩法:从模板选择、脚本调用到多租户

    但凡是学过Oracle的同学,对DBCA(Database Configuration Assistant, DBCA)都不会陌生,有了这个工具,使得创建数据库成为可能.而DBCA本身有图形和静默两种 ...

  6. js 判断提交表单

    <SCRIPT language=javascript> function check_book() { if(document.form1.Username.value=="& ...

  7. NullPointerException

    if(userName.equals("zhansan")){}   可能会报空指针异常

  8. HDU 4460 Friend Chains(map + spfa)

    Friend Chains Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total ...

  9. Video Pooling

    Video pooling computes video representation over the whole video by pooling all the descriptors from ...

  10. ActiveMQ的配置与使用

    1.什么是ActiveMQ MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应用程序通过写和检索出入列队的针对应用程序的数据(消息)来通信,而无需专用连接来 ...