用于DDS的正弦信号产生

上一篇 / 下一篇  2006-09-23 11:35:43 / 天气: 晴朗 / 心情: 高兴 / 个人分类:技术文章

#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("sindata.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,"END;");
    fclose(fp);
}

TAG: 技术文章

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-12-27  
 123456
78910111213
14151617181920
21222324252627
28293031   

数据统计

  • 访问量: 5046
  • 日志数: 24
  • 建立时间: 2006-08-18
  • 更新时间: 2006-09-23

RSS订阅

Open Toolbar