#include "stdio.h"<br>
#include "math.h"<br>
#define N 256 /* N is the DEPTH of the table(数据个数也就是一个周期采样点数)*/<br>
#define P 8 /* 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>
{printf("cannot open this file\n");<br>
exit(0);<br>
}<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); /* pow(x,y)表示x的y次方*/<br>
i=1;<br>
for(n=0;n<=N-1;n++,i++)<br>
{y=bias+amp*sin(n*3.1415936535/(N/2));<br>
if(fmod(n,N)==0) /* fmod(n,N)表示计算n/N的余数 */<br>
{fprintf(fp,"\n");}<br>
if(fmod(i,16)==1) {fprintf(fp,"\n%04x %04x: ",i,n);}<br>
fprintf(fp,"%04x",y);<br>
}<br>
fprintf(fp,"\nEND;");<br>
fclose(fp);<br>
} |