當前位置:編程學習大全網 - 編程語言 - 高分懸賞!急求!三角波,鋸齒,正弦波,脈沖的C語言程序代碼,不要單片機方面的,純C的!

高分懸賞!急求!三角波,鋸齒,正弦波,脈沖的C語言程序代碼,不要單片機方面的,純C的!

正弦波輸入 振幅,頻率,時步,相位

三角波鋸齒波輸入 振幅,坡1寬,坡2寬,無波寬,時步

三角波 w1=w2, 鋸齒波 w1 != w2.

程序沒有考慮時間 寬度w1=0 或 w2 =0,如果等於0,請給壹個非0值,例如 0.0000001.

脈沖方波,請自己模仿三角波程序計算。w期間等於amp,flat_t期間等於0.

#include <stdio.h>

#include <math.h>

void main()

{

double y[2048];

double pi,r;

double amp,f,phi,dt,t,x;

double w,flat_t,slop1,slop2,L,w1,w2;

int flag_w1=0,flag_w2=0;

long int i;

int N=2048;

char str[5];

pi = atan(1.0) * 4.0;

fprintf(stderr,"Enter sin or tri\n");

scanf("%s",&str[0]);

if ( strncmp(str,"sin",3) == 0)

{

fprintf(stderr,"enter Amp Hz delta_t phase\n");

fprintf(stderr,"for example: 1.0 10.0 0.001 1.414\n");

scanf("%lf %lf %lf %lf",&amp,&f,&dt,&phi);

for (i=0;i<N;i++) y[i]= amp * sin(2.0*pi * f * dt * i + phi );

for (i=0;i<N;i++) fprintf(stdout,"%lf\n",y[i]);

exit(0);

};

fprintf(stderr,"enter Amp w1 w2 flat_t dt\n");

fprintf(stderr,"for example: 1. 1. 1. 1. 0.01 \n");

scanf("%lf %lf %lf %lf %lf",&amp,&w1,&w2,&flat_t,&dt);

w = w1+w2;

L = w + flat_t;

slop1 = amp / w1;

slop2 = -amp / w2;

for (i=0;i<N;i++)

{

t = dt * (double) i;

x = t - L * (double) ( (int) (t / L));

if (x >= 0.0 && x <= w1) y[i] = slop1 * x;

if (x > w1 && x < w ) y[i] = amp + slop2 * (x - w1);

if (x >= w && x <= L ) y[i] = 0.0;

}

for (i=0;i<N;i++) fprintf(stdout,"%lf\n",y[i]);

exit(0);

}

  • 上一篇:Paakala編程和scratch編程的區別
  • 下一篇:天津東麗航訊集團是不是傳銷?
  • copyright 2024編程學習大全網