MATLAB生成.coe文件和.mif文件代码示例

.coe文件和.mif文件分别是XILINX和ALTERA用来初始ROM的文件
生成.coe文件的代码如下:

clear all;
close all;
clc;

BASE_FREQ = 450000000;
CARRIER = 90000000;
BAND = 50000;

fid_s = fopen('fm_tx_rom.coe', 'wt');
fprintf(fid_s, '%s\n', 'MEMORY_INITIALIZATION_RADIX = 16;');
fprintf(fid_s, '%s\n', 'MEMORY_INITIALIZATION_VECTOR =');

for (i=1:256)
    freq_wish = CARRIER + BAND*(i-1)/256;
    divider = BASE_FREQ / freq_wish;
    m=(divider-4)/(5-divider); 
    fprintf(fid_s, '%d', round(m));
    fprintf(fid_s, '%s', ',');
end
fclose(fid_s);
disp('===================转换完成=========================');

生成.mif文件的代码如下:

clear all;
close all;
clc;

BASE_FREQ = 450000000;
CARRIER = 90000000;
BAND = 50000;

fid_s = fopen('fm_tx_rom.mif', 'wt');
fprintf(fid_s, '%s\n', 'DEPTH = 256;');
fprintf(fid_s, '%s\n', 'WIDTH =16;');
fprintf(fid_s, '%s\n', 'ADDRESS_RADIX = UNS;');%UNS表示为十进制
fprintf(fid_s, '%s\n', 'DATA_RADIX = UNS;');
fprintf(fid_s, '%s\n', 'CONTENT BEGIN');

for (i=1:256)
    freq_wish = CARRIER + BAND*(i-1)/256;
    divider = BASE_FREQ / freq_wish;
    m=(divider-4)/(5-divider); 
    fprintf(fid_s, '%03d', i-1);
    fprintf(fid_s, '%s', ' : ');
    fprintf(fid_s, '%d', round(m));
    fprintf(fid_s, '%s\n', ';');
end
fclose(fid_s);
disp('===================转换完成=========================');

你可能感兴趣的:(MATLAB生成.coe文件和.mif文件代码示例)