复件 dss.c

来自「dds sine sheng c hengxu」· C语言 代码 · 共 31 行

C
31
字号
#include"stdio.h"
#include"math.h"
#define N 256        /* N is the DEPTH of the table(数据个数也就是一个周期采样点数) */
#define P 10                /* P is the Precision of data in the table(数据精度也就是一个数据的位数) */
void main()
{
FILE *fp;
double y,bias,amp;
int n;
if((fp=fopen("sine.c","w"))==NULL)
   {printf("cannot open this file\n");
    exit(0);
   }
  fprintf(fp,"WIDTH=10;\n");
  fprintf(fp,"DEPTH=256;\n");
  fprintf(fp,"ADDRESS_RADIX=DEC;\n");
  fprintf(fp,"DATA_RADIX=DEC;\n");
  fprintf(fp,"CONTENT BEGIN\n");
  bias = amp = pow(2,P-1)+0.5;         /* 原来误写为:pow(2,N-1)        */
  for(n=0;n<=N-1;n++)
   {y=bias+amp*sin(n*3.1415936535/(N/2));        /* 原来为128,已改成(N/2)        */
    if(fmod(n,10)==0)
      {fprintf(fp,"\n");}
    //fprintf(fp,"%4d:%4.0f;\n",n,y);
      fprintf(fp,"%4d\n",n);
	//fprintf(fp,"%4.0f\n",y);
   }
    fprintf(fp,"END;");
    fclose(fp);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?