标签:
Altera ROM支持HEX和mif格式文件,生成代码如下:clc;clear;close all;width = 10;depth = 2^width;t = linspace(0,6.28,depth);sin_val = sin(t);%cos_val = cos(t);sin_val = fix(sin_val*(2^width-1)/2 + 0.5); %四舍五入%cos_val = fix(cos_val*(2^width-1)/2 + 0.5);sin_val(find(sin_val<0))=sin_val(find(sin_val<0)) + 2^width; %将负数求反码addr = [0:depth - 1];file = fopen(‘sin.mif‘,‘wt‘);fprintf(file,‘WIDTH=%d;\n‘,width); %该格式对应于mif格式,最后不要变fprintf(file,‘DEPTH=%d;\n‘,depth);fprintf(file,‘\n‘);fprintf(file,‘ADDRESS_RADIX=UNS;\n‘);fprintf(file,‘DATA_RADIX=HEX;\n‘);fprintf(file,‘\n‘);fprintf(file,‘CONTENT BEGIN\n‘);for i=1:depthfprintf(file,‘ %d : %X;\n‘,addr(i), sin_val(i));endfprintf(file,‘\n‘);fprintf(file,‘END;\n‘);fclose(file);
标签:
原文地址:http://www.cnblogs.com/yfwblog/p/4515380.html