/*
-------------------------------------------------------------------------------------------------
ASSIGNMENT NO: 10
TITLE: Write a C program to polt magnitude and phase response of the given system.
-------------------------------------------------------------------------------------------------
*/
#include<math.h>
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
void main()
{
float Rn=0,In=0,Rd=0,Id=0,MAG,PHASE,temp,temp1;
int b1,a1,b[10],a[10],i,j,k,gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\\\tc\\\\bgi");cleardevice();
printf("\\nHow many coefficient for NUMERATOR: ");
scanf("%d",&b1);
for(i=0;i<b1;i++)
{
printf("b[%d]=",i);
scanf("%d",&b[i]);
}
printf("\\nHow many coefficient for DENOMINATOR: ");
scanf("%d",&a1);
for(i=0;i<a1;i++)
{
printf("a[%d]=",i);
scanf("%d",&a[i]);
}
cleardevice();
line(0,240,640,240);
outtextxy(50,50,"MAGNITUDE");
outtextxy(50,290,"PHASE");
line(10,10,10,220);
line(10,250,10,470);
line(0,113,630,113);
line(0,365,630,365);
for(k=10;k<630;k++)
{
Rn=Rd=In=Id=0;
Rn=b[0];Rd=a[0];
for(i=0;i<b1;i++)
{
Rn+=(b[i]*cos(k*i*3.14/180));
In+=(b[i]*sin(k*i*3.14/180));
}
for(i=0;i<a1;i++)
{
Rd+=(a[i]*cos(k*i*3.14/180));
Id+=(a[i]*sin(k*i*3.14/180));
}
temp=sqrt((In*In) +(Rn*Rn));
temp1=sqrt((Id*Id) +(Rd*Rd));
MAG=temp/temp1;
temp=(In/Rn);temp1=(Id/Rd);
PHASE=(atan(temp)-atan(temp1));
putpixel(k,120-(MAG*40),RED);
putpixel(k,120-(PHASE*40)+250,RED);
}
getch();
}