matlab 与 modelsim 联调 cic抽取滤波器
注:本设计的参数为:D=2,R=5,N=3;时钟频率为50mhz,输入信号为有符号8位,根据公式bmax=bin+N*log(2,R*D);可以得到bmax=18;
1,cic抽取滤波器原理
网上资料一大堆,不说了。重点在于传递函数,以及各个部分的结构。
2,simulink仿真
模型图
频谱仪显示结果
3,cic滤波器verilog 代码
module cic_dec(clk,rst_n,datain,dataout);
input clk,rst_n;
input [7:0] datain;
output [7:0] dataout;
reg [17:0] data_buff;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
data_buff<=0;
else
data_buff<={{10{datain[7]}},datain};
end
reg [17:0] integ1_result;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
integ1_result<=0;
else
integ1_result<=data_buff+integ1_result;
end
reg [17:0] integ2_result;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
integ2_result<=0;
else
integ2_result<=integ1_result+integ2_result;
end
reg [17:0] integ3_result;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
integ3_result<=0;
else
integ3_result<=integ2_result+integ3_result;
end
//integrator end
//decimation start
reg dec_flag;
reg [17:0] dec_result;
reg [2:0] cnt1;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
cnt1<=0;
else if(cnt1==3'd4)
cnt1<=0;
else
cnt1<=cnt1+1'b1;
end
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
dec_result<=0;
else if(cnt1==3'd4)
dec_result<=integ3_result;
end
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
dec_flag<=1'b0;
else if(cnt1==3'd4)
dec_flag<=1'b1;
else
dec_flag<=1'b0;
end
//decimation end
// comb filter begin
reg [2:0] cnt2;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
cnt2<=0;
else if(dec_flag)
cnt2<=0;
else
cnt2<=cnt2+1'b1;
end
reg [17:0] comb1_delay1;
reg [17:0] comb1_delay2;
reg [17:0] comb1_result;
always@(posedge clk or negedge rst_n)//first comb
begin
if(!rst_n)
begin
comb1_delay1<=0;
comb1_delay2<=0;
end
else if(cnt2==3'd3)
begin
comb1_delay1<=dec_result;
comb1_delay2<=comb1_delay1;
end
end
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
comb1_result<=0;
else if(dec_flag)
comb1_result<=dec_result-comb1_delay2;
end
reg [17:0] comb2_delay1;
reg [17:0] comb2_delay2;
reg [17:0] comb2_result;
always@(posedge clk or negedge rst_n)//second comb
begin
if(!rst_n)
begin
comb2_delay1<=0;
comb2_delay2<=0;
end
else if(cnt2==3'd3)
begin
comb2_delay1<=comb1_result;
comb2_delay2<=comb2_delay1;
end
end
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
comb2_result<=0;
else if(dec_flag)
comb2_result<=comb1_result-comb2_delay2;
end
reg [17:0] comb3_delay1;
reg [17:0] comb3_delay2;
reg [17:0] comb3_result;
always@(posedge clk or negedge rst_n)//third comb
begin
if(!rst_n)
begin
comb3_delay1<=0;
comb3_delay2<=0;
end
else if(cnt2==3'd3)
begin
comb3_delay1<=comb2_result;
comb3_delay2<=comb3_delay1;
end
end
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
comb3_result<=0;
else if(dec_flag)
comb3_result<=comb2_result-comb3_delay2;
end
reg [7:0] dataout_buff;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
dataout_buff<=0;
else
dataout_buff<=(comb3_result[17:0]+{!comb3_result[17],{9{comb3_result[17]}}})>>10;
end
assign dataout=dataout_buff;
endmodule
4,matlab产生正弦波形文件采样频率50m,正弦频率1m
0=1e6;
fs=50e6;
N=fs/f0;
n=0:N-1;
t=n/fs;
width=8;
sinwave=sin(2*pi*f0*t);
sindata = round(sinwave .* (2^(width-1) - 1));
for i=1:N
if(sindata(i)<0)
sindata(i)=2^width+sindata(i);
else
sindata(i)=sindata(i);
end
end
fid=fopen('sindata.txt','a');
for i=1:N
fprintf(fid,'%x \n',sindata(i));
i=i+1;
end
fclose(fid);
5,verilog读取波形文件产生正弦波
module sin_gen(clk,rst_n,sin_out);
input clk,rst_n;
output [7:0] sin_out;
parameter N = 50;
reg [7:0] mem[0:N-1];
initial
begin
$readmemh("sindata.txt",mem);
end
reg [7:0] sin_out_buff;
reg [5:0] i;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
sin_out_buff<=0;
i<=6'd0;
end
else
begin
sin_out_buff<=mem[i];
if(i==6'd49)
i<=6'd0;
else
i<=i+1'b1;
end
end
assign sin_out=sin_out_buff;
endmodule
6, testbench
`timescale 1ns/1ps
module testbench();
reg clk,rst_n;
initial
begin
clk=0;
forever #10 clk=~clk;
end
initial
begin
rst_n=0;
#50 rst_n=1'b1;
end
wire [7:0] sin_out;
sin_gen u0_sin_gen(.clk(clk),.rst_n(rst_n),.sin_out(sin_out));
wire [7:0] data_out;
cic_dec u0_cic_dec(.clk(clk),.rst_n(rst_n),.datain(sin_out),.dataout(data_out));
reg [10:0] cnt;
always@(posedge clk or negedge rst_n )
begin
if(!rst_n)
cnt<=0;
else if(cnt==11'd1024)
cnt<=cnt;
else
cnt<=cnt+1'b1;
end
integer fid;
initial
begin
fid=$fopen("dataout.txt","a");
end
always@(posedge clk )
begin
$fwrite(fid,"%x \n",data_out);
end
always@(posedge clk)
begin
if(cnt==11'd1024)
begin
$fclose(fid);
$stop;
end
end
endmodule
7,modelsim 仿真波形
matlab 与 modelsim 联调 cic抽取滤波器的更多相关文章
- CIC 抽取滤波器 Verilog Code
采用流水线结构的CIC 抽取滤波器结构如下: // 三级CIC抽取器实例:cic3_decimator.V module cic3_decimator(clk, x_in, y_out); param ...
- 通过文件读写方式实现Matlab和Modelsim的联合仿真
虽然Modelsim的功能非常强大,仿真的波形可以以多种形式进行显示,但是当涉及到数字信号处理的算法的仿真验证的时候,则显得有点不足.而进行数字信号处理是Matlab的强项,不但有大量的关于数字信号处 ...
- matlab与modelsim中的文件操作函数
matlab中 fscanf和fpintf是一对,用fprintf写的必须用fscanf来读. fread和fwrite是一对,用fwrite写的必须用fread来读. 同样的数据,使用fprintf ...
- Quartus II 与 Modelsim 联调【转】
Quartus II 9.0版本的时候软件还有自带的仿真工具,现在安装的是11.0以上版本,才发现 Quartus II 11.0以上取消了软件自带的波形仿真工具,因此需要波形仿真就要调用专业的仿真工 ...
- 基于FPGA的音频信号的FIR滤波(Matlab+Modelsim验证)
1 设计内容 本设计是基于FPGA的音频信号FIR低通滤波,根据要求,采用Matlab对WAV音频文件进行读取和添加噪声信号.FFT分析.FIR滤波处理,并分析滤波的效果.通过Matlab的分析验证滤 ...
- Quartus prime16.0 与modelsim ae 联调
前言 quartus和modelsim联调对仿真还是很方便的,当然最好是quartus干综合到烧录的活,modelsim单独仿真.而且ae版的性能比se版差. 流程: 1.配置modelsim ae路 ...
- FIR滤波器(1)- 基础知识
FIR滤波器广泛应用于数字信号处理中,主要功能就是将不感兴趣的信号滤除,留下有用信号.FIR滤波器是全零点结构,系统永远稳定:并且具有线性相位的特征,在有效频率范围内所有信号相位上不失真.在无线通信收 ...
- 转载论文关于fir滤波器的fpga实现
摘 要 本文讨论的FIR滤波器因其具有严格的线性相位特性而得到广泛的应用.在工程实践中,往往要求信号处理具有实时性和灵活性,本论文研究FIR的FPGA解决方案正体现了电子系统的微型化和单片化. 本论文 ...
- 使用MATLAB对图像处理的几种方法(上)
实验一图像的滤波处理 一.实验目的 使用MATLAB处理图像,掌握均值滤波器和加权均值滤波器的使用,对比两种滤波器对图像处理结果及系统自带函数和自定义函数性能的比较,体会不同大小的掩模对图像细节的影响 ...
随机推荐
- Servlet+MyBatis项目转Spring Cloud微服务,多数据源配置修改建议
一.项目需求 在开发过程中,由于技术的不断迭代,为了提高开发效率,需要对原有项目的架构做出相应的调整. 二.存在的问题 为了不影响项目进度,架构调整初期只是把项目做了简单的maven管理,引入spri ...
- PHP面向对象程序设计之接口(interface)
接口(interface)是抽象方法和静态常量定义的集合.接口是一种特殊的抽象类,这种抽象类中只包含抽象方法和静态常量. 为什么说接口是一种特殊的抽象类呢?如果一个抽象类里面的所有的方法都是抽象方法, ...
- Spring_使用 JdbcTemplate和JdbcDaoSupport-代码
applicationContext.xml <?xml version="1.0" encoding="UTF-8"?><beans xml ...
- JAVA集合类汇总 - 转载
一.集合与数组 数组(可以存储基本数据类型)是用来存现对象的一种容器,但是数组的长度固定,不适合在对象数量未知的情况下使用. 集合(只能存储对象,对象类型可以不一样)的长度可变,可在多数情况下使用. ...
- Android -- junit测试框架,logcat获取log信息
1. 相关概念 白盒测试: 知道程序源代码. 根据测试的粒度分为不同的类型 方法测试 function test 单元测试 unit test 集成 ...
- JavaWeb -- Struts2 验证框架
1. 验证框架 示例 表单提交Jsp, reg.jsp <%@ page language="java" contentType="text/html; chars ...
- Android两个Activity之间的数据交换
1. 不带数据 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceS ...
- colorlog的三个例子
例1:默认的log_colors import logging from logging.handlers import RotatingFileHandler from colorlog impor ...
- java环信服务端注册IM代码
下载环信api代码 https://github.com/easemob/emchat-server-examples 里面包含各种语言版本,我只下载了java版emchat-server-java ...
- DGA GAN——GAN在安全中的应用
DGA的模型:https://github.com/Yuren-Zhong/DeepDGA CNN.LSTM.双向LSTM 论文可以看https://openreview.net/pdf?id=BJL ...