⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 傅立叶级数表矩形波.txt

📁 信号系统常用程序.卷积/傅立叶级数/频谱分析/调制解调等
💻 TXT
字号:
/*==================================================================*/
/*                傅立叶级数表矩形波并计算误差                      */
/*                              ------- written by chenzhiyu        */
/*==================================================================*/
#include "graphics.h"
#include "conio.h"
#include "math.h"
#include "stdio.h"
#define N 620
#define PI 3.1415926
#define E 80
#define T ((getmaxx()-20)/3)
/*--------------------------------------------------------------------*/
/*                        void background                             */
/*--------------------------------------------------------------------*/                               

void background()
{
	setbkcolor(3);
	setfillstyle(1,6);
	bar(5,5,getmaxx()-5,getmaxy()/2-5);
	bar(5,getmaxy()/2+5,getmaxx()-5,getmaxy()-5);
	line(0,getmaxy()/4,getmaxx(),getmaxy()/4);
	line(0,getmaxy()*3/4,getmaxx(),getmaxy()*3/4);
	line(getmaxx()/2,0,getmaxx()/2,getmaxy());
}
/*---------------------------------------------------------------------*/
/*                           void main                                 */
/*---------------------------------------------------------------------*/    

main()
{
	float y0[N],y01[N];
	float y[N],x[N],y1[N];
	float error[N];
	float b;
	float tao;
	int A;
	int num;
	int i,j;

	int gmode;
	int gdriver=DETECT;
	printf("please input bl (tao=bl*T and bl<=1)=>");
	scanf("%f",&b);
	printf("\nplease input num=>");
	scanf("%d",&num);

	initgraph(&gdriver,&gmode,"\\tc\\bin");
	setcolor(LIGHTGREEN);
	tao=b*T;
	A=(int)(tao);

	for(i=0;i<N;i++)
	   {
			x[i]=i;
			y0[i]=0;
			y01[i]=getmaxy()/4+y0[i];
	   }
	for(i=0;i<=A;i++)
	{
		y0[(int)(getmaxx()/2-A/2+i)]=E;
		y0[(int)(getmaxx()/2+T-A/2+i)]=E;
		y0[(int)(getmaxx()/2-T-A/2+i)]=E;
		y01[(int)(getmaxx()/2-A/2+i)]=-y0[(int)(getmaxx()/2-A/2+i)]+getmaxy()/4;
		y01[(int)(getmaxx()/2+T-A/2+i)]=-y0[(int)(getmaxx()/2+T-A/2+i)]+getmaxy()/4;
		y01[(int)(getmaxx()/2-T-A/2+i)]=-y0[(int)(getmaxx()/2-T-A/2+i)]+getmaxy()/4;

	}

	for(j=0;j<N;j++)
	{
		y[j]=0;
		y1[j]=-y[j]+getmaxy()/4;
		error[j]=0;
	}

	for(i=1;i<=num;i++)
	{
		background();
		moveto(x[10],y01[10]);
		for(j=10;j<N;j++)
			lineto(x[j],y01[j]);

		for(j=0;j<N;j++)
		{
			y[j]=y[j]+2*E*sin(i*PI*b)/(i*PI)*cos(i*6*PI*(j-getmaxx()/2)/(getmaxx()-20));
		}
		for(j=0;j<N;j++)
		{
			y1[j]=-(y[j]+E*b)+getmaxy()/4;
		}
		moveto(x[10],y1[10]);
		for(j=10;j<N;j++)
			lineto(x[j],y1[j]);
		for(j=0;j<N;j++)
		{
			error[j]=y1[j]-y01[j]+getmaxy()*3/4;
		}
		moveto(x[10],error[10]);
		for(j=10;j<N;j++)
			lineto(x[j],error[j]);

		printf("\rnumber is %d",i);
		outtextxy(getmaxx()/2,10,"function");
		outtextxy(getmaxx()/2,getmaxy()/2+20,"error");
		getch();
	}

	getch();
	closegraph();
	return 0;
}

⌨️ 快捷键说明

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