document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2. -------------------------------------------------------------------------------------------------
  3.  ASSIGNMENT NO: 10
  4.  TITLE: Write a C program to polt magnitude and phase response of the given system.
  5. -------------------------------------------------------------------------------------------------
  6. */
  7.  
  8. #include<math.h>
  9. #include<conio.h>
  10. #include<stdio.h>
  11. #include<graphics.h>
  12.  
  13. void main()
  14. {
  15.  float Rn=0,In=0,Rd=0,Id=0,MAG,PHASE,temp,temp1;
  16.  int b1,a1,b[10],a[10],i,j,k,gd=DETECT,gm;
  17.  initgraph(&gd,&gm,"c:\\\\tc\\\\bgi");cleardevice();
  18.  printf("\\nHow many coefficient for NUMERATOR: ");
  19.  scanf("%d",&b1);
  20.  for(i=0;i<b1;i++)
  21.  {
  22.     printf("b[%d]=",i);
  23.     scanf("%d",&b[i]);
  24.  }
  25.  printf("\\nHow many coefficient for DENOMINATOR: ");
  26.  scanf("%d",&a1);
  27.  for(i=0;i<a1;i++)
  28.  {
  29.     printf("a[%d]=",i);
  30.     scanf("%d",&a[i]);
  31.  }
  32.  
  33.  cleardevice();
  34.  line(0,240,640,240);
  35.  outtextxy(50,50,"MAGNITUDE");
  36.  outtextxy(50,290,"PHASE");
  37.  line(10,10,10,220);
  38.  line(10,250,10,470);
  39.  line(0,113,630,113);
  40.  line(0,365,630,365);
  41.  for(k=10;k<630;k++)
  42.  {
  43.     Rn=Rd=In=Id=0;
  44.     Rn=b[0];Rd=a[0];
  45.     for(i=0;i<b1;i++)
  46.     {
  47.         Rn+=(b[i]*cos(k*i*3.14/180));
  48.         In+=(b[i]*sin(k*i*3.14/180));
  49.     }
  50.     for(i=0;i<a1;i++)
  51.     {
  52.         Rd+=(a[i]*cos(k*i*3.14/180));
  53.         Id+=(a[i]*sin(k*i*3.14/180));
  54.     }
  55.     temp=sqrt((In*In) +(Rn*Rn));
  56.     temp1=sqrt((Id*Id) +(Rd*Rd));
  57.     MAG=temp/temp1;
  58.     temp=(In/Rn);temp1=(Id/Rd);
  59.     PHASE=(atan(temp)-atan(temp1));
  60.     putpixel(k,120-(MAG*40),RED);
  61.     putpixel(k,120-(PHASE*40)+250,RED);
  62.  }
  63.  getch();
  64. }
');