当前位置:网站首页>如何将matlab数据导入modelsim仿真
如何将matlab数据导入modelsim仿真
2022-07-30 05:48:00 【FPGA-信号处理】
目的
本方法主要适用于在matlab和modelsim联合仿真时有用,比如matlab生成的adc数据作为modelsim 仿真时的adc激励数据,或者modelsim生成的ram数据也可以在仿真时加载进modelsim进行仿真,下面我们将以matlab生成adc原始数据导入modelsim来演示。
matlab代码
生成adc数据的代码:
clc;
clear all;
close all;
fs = 250e6; % adc采样率
fout = 10e6; % 生成信号频率
len = 8192; % 生成信号长度
t = 0:1/fs:(len-1)/fs; % 采样点的时间片
amp = 25000; % adc信号幅度
adc_dat = cos(2*pi*fout*t); % adc数据
adc_dat = awgn(adc_dat, 40);% 对生成信号加入噪声
adc_dat = round(adc_dat*amp);% 量化adc数据
% 画出信号的时域和频域图
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);
% 存储ADC数据
u_adc_dat = sign2com(adc_dat, 16);
fp = fopen('adc_dat.bin', 'w');
fprintf(fp, '%04x\n',u_adc_dat);
fclose all;
adc数据的频域和时域图
- 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 ;
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
endmodule
- 仿真效果
- 总结
此方法非常适用于matlab生成的数据作为激励源。代替掉模块内部需要产生数据源的模块。
边栏推荐
- Kunlun State Screen Production (Serialization 5) --- Basics (serial port reception, text and light display)
- 爬楼梯C语言
- lcd1602调试
- ssh script space character conversion
- QT weekly skills (3)~~~~~~~~~ serial port addition
- 表格比手机屏幕宽时不压缩,可左右滚动,格子内容不换行
- Biotin-SS-NHS ester|生物素-二硫键-活性酯|CAS:122266-55-1具有良好的水溶性
- (*(void (*)())0)()的解读
- 图扑软件携手华为云再创合作共赢新局面
- xxx is not in the sudoers file.This incident will be reported error
猜你喜欢
随机推荐
Unity Shader 标准光照模型
四、6、前缀、中缀、后缀表达式(逆波兰表达式)
数码管动态显示及模块化编程
Deep Interpretation of void (*signal(int , void(*)(int)))(int) in "C Traps and Defects"
xftp的简单使用
力扣题解7.27
QT weekly skills (3)~~~~~~~~~ serial port addition
基于STM32F103的消防系统之火焰传感器
Insert map data efficiently
SSH-RSA密钥
VsCode与Sublime编辑器优缺点对比
Comparison of advantages and disadvantages of VsCode and Sublime editors
ThreeJS导入外部obj和mtl
rsync使用方法之坑
单向链表的操作(带头结点)
测试第二题
《C陷阱和缺陷》void (*signal(int , void(*)(int)))(int)的深刻解读
Kunlun state screen production (serial 3) - based article (button serial port to send)
FPGA parsing B code----serial 2
C#二叉树的遍历方法(通过递归)