源: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滤波器的fpga实现
摘 要 本文讨论的FIR滤波器因其具有严格的线性相位特性而得到广泛的应用.在工程实践中,往往要求信号处理具有实时性和灵活性,本论文研究FIR的FPGA解决方案正体现了电子系统的微型化和单片化. 本论文 ...
- FIR滤波器的FPGA实现方法
FIR滤波器的FPGA实现方法 2011-02-21 23:34:15 来源:互联网 非常重要的基本单元.近年来,由于FPGA具有高速度.高集成度和高可靠性的特点而得到快速发展.随着现代数字 ...
- 数字信号处理实验(六)——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 ...
- FIR滤波器(1)- 基础知识
FIR滤波器广泛应用于数字信号处理中,主要功能就是将不感兴趣的信号滤除,留下有用信号.FIR滤波器是全零点结构,系统永远稳定:并且具有线性相位的特征,在有效频率范围内所有信号相位上不失真.在无线通信收 ...
- FIR滤波器设计
FIR滤波器的优越性: 相位对应为严格的线性,不存在延迟失真,仅仅有固定的时间延迟: 因为不存在稳定性问题,设计相对简单: 仅仅包括实数算法,不涉及复数算法,不须要递推运算,长度为M,阶数为M-1,计 ...
- FIR滤波器工作原理(算法)以及verilog算法实现(包含与IIR的一些对比)
滤波器在2017年IC前端的笔试中,出现频率十分的高.不论今后是否会涉及,还是要记住一些会比较好.接下来就将从这四个方面来讲解,FIR数字滤波器的工作原理(算法)与verilog实现. ·什么是FIR ...
- matlab进行FIR滤波器设计(一)
来源:https://blog.csdn.net/leokingszx/article/details/80041910 在实际的应用中,有时需要使用FIR根据完成一些特定功能,比如近似一阶RC低通电 ...
- IIR滤波器和FIR滤波器的区别与联系zz
-------------------------------------------------------------------------------------------------- ...
- CIC and Fir 滤波器的级联
在FDATool中 CIC 和 Fir 级联滤波器的设计 1 设计CIC滤波器的幅频特性曲线如下 2.设计FIR 滤波器的幅频特性曲线如下 3.总的特性曲线如下 4.把通带部分放大后的图,比较平坦
随机推荐
- Angularjs中的ng-class
在angular中为我们提供了3种方案处理class:1:scope变量绑定.(不推荐使用)2:字符串数组形式.3:对象key/value处理. 我们继续其他两种解决方案:1字符串数组形式是针对cla ...
- sysbench使用教程【转载】
水晶命匣 2016-08-16 20:02 一.环境描述 此次使用的虚拟机环境如下所示: CPU:双核 2.4GHz 内存:4 GB 硬盘:120 GB IP:192.168.21.129 操作系统: ...
- jni中的参数含义
#include <jni.h> JNIEXPORT jstring JNICALL Java_com_example_hellojni_MainActivity_helloFromC ( ...
- adb端口被占用
程序不能执行,kill掉任务管理器里面adb服务,重新连接设备仍然有错 查到可能是adb端口被占用 查看adb用的是哪个端口:C:\Users\wanglin>adb nodaemon serv ...
- 转 Apache Ant 实现自动化部署
Apache Ant 实现自动化部署 Apache Ant 实现自动化部署 http://www.netkiller.cn/journal/java.ant.html Mr. Neo Chen (陈景 ...
- C++虚函数的新用法
1.今天在segmentfault上看到了一个C++虚函数的新用法,先上代码 #include <iostream> using namespace std; class B { publ ...
- Spring Boot 系列教程7-EasyUI-datagrid
jQueryEasyUI jQuery EasyUI是一组基于jQuery的UI插件集合体,而jQuery EasyUI的目标就是帮助web开发者更轻松的打造出功能丰富并且美观的UI界面.开发者不需要 ...
- Hibernate 系列教程3-单表操作
工程截图 hibernate.cfg.xml <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Conf ...
- jquery的校验规则的方法
//validate 选项*********************************************************** $("form").validat ...
- js 弹层 提示
<!DOCTYPE html><html style="height: 100%;"><head lang="en"> &l ...