2个回答
展开全部
正弦波输入 振幅,频率,时戚销步,相位
三角波锯齿波输入 振幅,坡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",&,&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",&,&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);
}
三角波锯齿波输入 振幅,坡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",&,&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",&,&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);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询