当前位置:网站首页>如何将modelsim仿真数据存成文件
如何将modelsim仿真数据存成文件
2022-07-30 05:48:00 【FPGA-信号处理】
目的
如何将modelsim仿真的数据存储成文件供matlab分析,在实际工程应用中很多时候我们需要分析仿真过程中新产生的数据,在用肉眼不能直接观察时就需要将数据存成文件使用第三方软件进行更直观的分析。下面分别使用matlab和modelsim联合仿真,将modelsim的仿真数据存成文件使用matlab对数据进行分析。
verilog代码
`timescale 1ns/1ps
module testbench();
localparam LEN = 8192 ;
reg [15:0] adc_dat[8191:0] ;
reg clk ;
reg rst ;
reg [12:0] cnt ;
reg [15:0] sim_dat ;
reg [15:0] wr_cnt ;
initial begin
$readmemh("./adc_dat.bin", adc_dat, 0, LEN-1);
end
initial begin
clk = 0;
rst = 1;
cnt = 0;
sim_dat = 0;
#1000;
rst = 0;
end
always #2.00 clk = ~clk ;
[email protected](posedge clk)
begin
if(rst) begin
cnt <= 0;
end
else begin
cnt <= cnt + 1;
sim_dat <= adc_dat[cnt];
end
end
integer fp;
initial begin
fp =$fopen("adc_export_dat.bin", "w");
end
[email protected](posedge clk)
begin
if(rst) begin
wr_cnt <=0;
end
else begin
if(wr_cnt < 8192) begin
wr_cnt <=wr_cnt + 1;
end
if(wr_cnt < 8192) begin
$fwrite(fp, "%d\n", $signed(adc_dat[wr_cnt]));
end
end
end
endmodule
从代码中可以看出我们是将文件读进来的数据直接存成文件(文件的读取过程见上一篇文章如何将matlab生成数据导入modelsim进行仿真)
matlab分析数据代码
clc;
clear all;
close all;
adc_dat = load('adc_export_dat.bin');
len = length(adc_dat);
subplot(211);
plot(adc_dat);
subplot(212);
fft_data = abs(fft(adc_dat, len));
fft_data = 20*log10(fft_data);
fft_data = fft_data - max(fft_data);
plot(fft_data);
matlab分析数据结果

边栏推荐
猜你喜欢

Word使用中常用的快捷键

Unity Gizmos扩展:线框圆

antd table Summary总结栏置顶

一种新的DNA生物素系统Biotin LC hydrazide|CAS:109276-34-8|(+)-生物素酰胺基己酸肼

IO进程线程->文件IO->day2

Cas 80750-24-9,去硫代生物素 N-羟基琥珀酰亚胺,淡黄色固体

Biotin-C6-amine_N-生物素基-1,6-己二胺_CAS:65953-56-2_100mg

xxx is not in the sudoers file.This incident will be reported错误
![[Common usage of markdown]](/img/4b/3cb17b1dafe095e2f45510b41186fd.png)
[Common usage of markdown]

二、1稀疏sparsearray数组
随机推荐
VsCode连接远程服务器并修改文件代码
VsCode与Sublime编辑器优缺点对比
测试第一题
sizeof和strlen最全区别,以及指针和数组运算解析
51数码管显示
---------手撕二叉树,完成二叉树的前中后序遍历,以及前中后序查找
数码管动态显示及模块化编程
------实现二叉搜索树BST
vscode 设置 sublime 的主题
com.alibaba.datax.common.exception.DataXException: Code:[ESWriter-03]
【已解决:el-input标签无法输入或不显示文字】
lcd1602调试
Biotin-PEG4-SS-Alkyne_1260247-54-8_生物素-PEG4-SS-炔烃
【Exhibition of some projects】
二、1稀疏sparsearray数组
迷宫问题----经典回溯法解决
Knowledge of the day: handwritten deep copy and shallow copy (solves the problem of circular references)
IEEE在指定期刊下搜索相关论文
FPGA parsing B code----serial 1
无法完成包的安装npm ERR! Refusing to install package with name “moment“ under a package also called “moment“