document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2. -------------------------------------------------------------------------------------------------
  3.  Assignment No .: 09
  4.  Title .: Draw a pole zero plot from a given system function H(Z) expressed as rational function. (Display pole zero table and pole zero plot)
  5. -------------------------------------------------------------------------------------------------
  6. */
  7.  
  8. #include<stdio.h>
  9. #include<conio.h>
  10. #include<math.h>
  11. #include<graphics.h>
  12.  
  13. void main()
  14. {
  15.     int M,N,a[10],b[10],i,j,delta,r;
  16.     float pr[10],pi[10],zr[10],zi[10],x,y;
  17.     int gd=DETECT,gm;
  18.     clrscr();
  19.     printf("\\nEnter the no.of terms in numerator:");
  20.     scanf("%d",&M);
  21.     printf("\\nEnter the no.of terms in donominator:");
  22.     scanf("%d",&N);
  23.     printf("\\nEnter the co-efficient of 1\'st polynomial:");
  24.     for(i=0;i<M;i++)
  25.     {
  26.         if(i==0)
  27.            printf("\\nco-efficient of z^%d:",i);
  28.         else
  29.            printf("\\nco-efficient of z^%d:",-i);
  30.            scanf("%d",&a[i]);
  31.     }
  32.     printf("\\nEnter the co-efficient of 2\'nd polynomial:");
  33.     for(i=0;i<N;i++)
  34.     {
  35.         if(i==0)
  36.            printf("\\nco-efficient of z^%d:",i);
  37.         else
  38.            printf("\\nco-efficient of z^%d:",-i);
  39.            scanf("%d",&b[i]);
  40.     }
  41.     printf("\\n\\nConvert into positive powers of z.");
  42.     printf("\\n Multiply both polynomials with highest power of z");
  43.     printf("\\n\\nh(z)=");
  44.     i=M-1;
  45.     for(i=0;i<M;i++)
  46.     {
  47.         printf("%z^%d",a[i],j);
  48.         j--;
  49.     }
  50.     printf("\\n\\t-----------------------------\\n\\t");
  51.     j=N-1;
  52.     for(i=0;i<N;i++)
  53.     {
  54.         printf("%z^%d",b[i],j);
  55.         j--;
  56.     }
  57.     //calculate poles & zeros
  58.     //zeros:
  59.     delta=(a[1]*a[1])-(4*a[0]*a[2]);
  60.     i=0;
  61.     if(delta>=0)
  62.     {
  63.         zr[i]=(-a[1]+sqrt(abs(delta)))/(2*a[0]);
  64.         zi[i]=0;
  65.         i++;
  66.  
  67.         zr[i]=(-a[1]-sqrt(abs(delta)))/(2*a[0]);
  68.         zi[i]=0;
  69.     }
  70.     else
  71.     {
  72.         zr[i]=(-a[1])/(2*a[0]);
  73.         zi[i]=sqrt(abs(delta))/(2*a[0]);
  74.         i++;
  75.  
  76.         zr[i]=(-a[1])/(2*a[0]);
  77.         zi[i]=(-sqrt(abs(delta)))/(2*a[0]);
  78.     }
  79.     //poles:
  80.     delta=0;
  81.     delta=(b[1]*b[1])-(4*b[0]*b[2]);
  82.     i=0;
  83.     if(delta>=0)
  84.     {
  85.         pr[i]=(-b[1]+sqrt(abs(delta)))/(2*b[0]);
  86.         pi[i]=0;
  87.         i++;
  88.  
  89.         pr[i]=(-b[1]-sqrt(abs(delta)))/(2*b[0]);
  90.         pi[i]=0;
  91.     }
  92.     else
  93.     {
  94.         pr[i]=(-b[1])/(2*b[0]);
  95.         pi[i]=sqrt(abs(delta))/(2*b[0]);
  96.         i++;
  97.  
  98.         pr[i]=(-b[1])/(2*b[0]);
  99.         pi[i]=(-sqrt(abs(delta)))/(2*b[0]);
  100.     }
  101.     initgraph(&gd,&gm,"");
  102.     printf("\\n\\nThe zeros are:");
  103.     for(i=0;i<M-1;i++)
  104.     {
  105.         printf("(%f+%f)",zr[i],zi[i]);
  106.     }
  107.     printf("\\n\\nThe poles are:");
  108.     for(i=0;i<N-1;i++)
  109.     {
  110.         printf("(%f+%f)",pr[i],pi[i]);
  111.     }
  112.     line(100,250,500,250);
  113.     line(300,50,300,500);
  114.     circle(300,250,100);
  115.     outtextxy(500,250,"x-axis");
  116.     outtextxy(300,50,"y-axis");
  117.     //plot zeros
  118.     for(i=0;i<M-1;i++)
  119.     {
  120.         x=300+(zr[i]*100);
  121.         y=250-(zi[i]*100);
  122.         putpixel(x,y,15);
  123.         circle(x,y,5);
  124.         outtextxy(x+7,y-7,"z");
  125.     }
  126.     //plot poles
  127.     for(i=0;i<N-1;i++)
  128.     {
  129.         x=300+(pr[i]*100);
  130.         y=250-(pi[i]*100);
  131.         putpixel(x,y,15);
  132.         line(x-5,y-5,x+5,y+5);
  133.         line(x+5,y-5,x-5,y+5);
  134.         outtextxy(x+7,y-7,"p");
  135.     }
  136.     getch();
  137.     closegraph();
  138. }
');