• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

matlab与modelsim联调cic抽取滤波器

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

注:本设计的参数为: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 仿真波形

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi 7中对StretchBlt, StretchDIBits, DrawDibDraw, BitBlt 的性能测试 - 原创 ...发布时间:2022-07-18
下一篇:
Delphi json解析相关发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap