usd 发表于 2010-6-26 02:50:06

如何初始化LPM_ROM

本帖最后由 fpgaw 于 2010-7-11 11:55 编辑

怎么初始化LPM_ROM,数据位为8位.深度为256,怎么用C语言或是MATLAB编写MIF文件

ICE 发表于 2010-6-26 04:14:15

#include "stdio.h"<br>
#include "math.h"<br>
#define N 256&nbsp; &nbsp;&nbsp;&nbsp;/* N is the DEPTH of the table(数据个数也就是一个周期采样点数)*/<br>
#define P 8&nbsp; &nbsp;&nbsp; &nbsp;/* P is the Precision of data in the table(数据精度也就是一个数据的位数)*/<br>
void main()<br>
{<br>
FILE *fp;<br>
double y,bias,amp;<br>
int n,i;<br>
if((fp=fopen("sindata.mif","w"))==NULL)<br>
&nbsp; &nbsp;{printf("cannot open this file\n");<br>
&nbsp; &nbsp; exit(0);<br>
&nbsp; &nbsp;}<br>
fprintf(fp,"WIDTH=P;\n");<br>
fprintf(fp,"DEPTH=N;\n");<br>
fprintf(fp,"ADDRESS_RADIX=DEC;\n");<br>
fprintf(fp,"DATA_RADIX=DEC;\n");<br>
fprintf(fp,"CONTENT BEGIN\n");<br>
bias = amp = pow(2,P-1);&nbsp; &nbsp; /* pow(x,y)表示x的y次方*/<br>
i=1;<br>
for(n=0;n&lt;=N-1;n++,i++)<br>
&nbsp; &nbsp; {y=bias+amp*sin(n*3.1415936535/(N/2));<br>
&nbsp; &nbsp;&nbsp;&nbsp;if(fmod(n,N)==0)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;/* fmod(n,N)表示计算n/N的余数 */<br>
&nbsp; &nbsp;&nbsp; &nbsp; {fprintf(fp,"\n");}<br>
&nbsp; &nbsp;&nbsp;&nbsp;if(fmod(i,16)==1) {fprintf(fp,"\n%04x %04x: ",i,n);}<br>
&nbsp; &nbsp;&nbsp;&nbsp;fprintf(fp,"%04x",y);<br>
&nbsp; &nbsp; }<br>
&nbsp; &nbsp; fprintf(fp,"\nEND;");<br>
&nbsp; &nbsp; fclose(fp);<br>
}

usb 发表于 2010-6-26 06:08:53

同问同问啊

Sunlife 发表于 2015-6-17 10:56:35

fprintf(fp,"WIDTH=P;\n");<br>
fprintf(fp,"DEPTH=N;\n");<br>
fprintf(fp,"ADDRESS_RADIX=DEC;\n");<br>
fprintf(fp,"DATA_RADIX=DEC;\n");<br>
fprintf(fp,"CONTENT BEGIN\n");<br>
bias = amp = pow(2,P-1);&nbsp; &nbsp; /* pow(x,y)表示x的y次方*/<br>
页: [1]
查看完整版本: 如何初始化LPM_ROM