当前位置:网站首页>如何将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分析数据结果

边栏推荐
猜你喜欢
![[Punctuality Atom] Learning and use of IIC (unfinished...)](/img/b7/325cad848eacee67c56c6cad321bd0.png)
[Punctuality Atom] Learning and use of IIC (unfinished...)

基于STM32F103的消防系统之驱动电机风扇

The IEEE under the specified journal search related papers

IO进程线程->目录IO->day3

进制详解(二进制、八进制、十进制、十六进制详解及相互转换,位运算)

VSCode hides the left activity bar

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

二、1稀疏sparsearray数组

C 语言之学生管理系统-多文件编程

QT weekly skills (3)~~~~~~~~~ serial port addition
随机推荐
无法完成包的安装npm ERR! Refusing to install package with name “moment“ under a package also called “moment“
The IEEE under the specified journal search related papers
矩阵键盘
js 替换字符串中所有 “ 引号 —— 数据处理
js高级学习笔记(详细)
QT serial port dynamically displays a large number of data waveform curves in real time (5) ======== "Final perfect solution version"
Cannnot download sources不能下载源码百分百超详细解决方案
Written before the official account - QT, ARM, DSP, microcontroller, power electronics and transmission!
VSCode hides the left activity bar
DADPS-生物素-炔基_CAS:2241685-22-1试剂反应原理
THREEJS辉光与景深特效
进制详解(二进制、八进制、十进制、十六进制详解及相互转换,位运算)
Simple use of xftp
基于THREEJS场景中模型局部辉光效果
THREEJS导入外部OBJ+MTL后内存优化
每日一知识:手写深拷贝和浅拷贝(解决了循环引用的问题)
图扑数字孪生青岛城轨,赋能智慧交通低碳发展
测试第一题
Kunlun State Screen Production (Serialization 5) --- Basics (serial port reception, text and light display)
四、6、前缀、中缀、后缀表达式(逆波兰表达式)