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处理图像,掌握均值滤波器和加权均值滤波器的使用,对比两种滤波器对图像处理结果及系统自带函数和自定义函数性能的比较,体会不同大小的掩模对图像细节的影响 ...
随机推荐
- COS-8文件系统
操作系统(Operating System,简称OS)是管理和控制计算机硬件与软件资源的计算机程序,是直接运行在“裸机”上的最基本的系统软件,任何其他软件都必须在操作系统的支持下才能运行. 操作系 ...
- SMM+maven下的log4j配置打印sql
1加入依赖包 <!--LOG4日志 start --> <dependency> <groupId>org.slf4j</groupId> <ar ...
- PasswordHasher 算法
public override PasswordVerificationResult VerifyHashedPassword(string hashedPassword, string provid ...
- js实现继承的方式
[原文] 前言 JS作为面向对象的弱类型语言,继承也是其非常强大的特性之一.那么如何在JS中实现继承呢?让我们拭目以待. JS继承的实现方式 既然要实现继承,那么首先我们得有一个父类,代码如下: // ...
- JavaWeb -- Struts2 验证框架
1. 验证框架 示例 表单提交Jsp, reg.jsp <%@ page language="java" contentType="text/html; chars ...
- Java EE启示录
前言 最近的这段时间一直在学习Java EE,刚刚完成了从0到1的蜕变,所以顺便整理一下我所了解到的Java EE,给刚入门学习的新人一些头绪,而所谓“启示录”,就是这个意思. 一.Java EE是什 ...
- scala学习手记40 - 使用case类
前面两节我们已经多次接触过case关键字了.case关键字不仅可以用在match/case中来执行模式匹配,也可以用来修饰类.不过用case修饰的类也主要是用来做模式匹配.在上一节曾经提到过match ...
- TCP_AIO_Server_ZC_01
ZC: 这个例子是,1个skt 投递 1个未决的接收操作 1.package aio.Client; 1.1.这是一个 测试的客户端的代码: package aio.Client; import ja ...
- Kubernetes 在知乎上的应用
从 Mesos 到 Kubernetes 之前的调度框架是基于 Mesos 自研的.采用的语言是 Python.运行了大概两年多的时间了,也一直比较稳定.但随着业务的增长,现有的框架的问题逐渐暴露. ...
- Windows Desktop Optimization.bat
界面: github: https://github.com/m2nlight/WindowsDesktopOptimization Config Service [Disabled] Windows ...