Signals ans Systems ,Elements digital signal Processing , Continuous time and discrete time signals , Sampling Theorem , Discrete time signals , Discrete time systems , Z transform , Convolution and correlation.

Posted by fasxxzczc on Thursday 22 March 2012

Signals ans Systems ,Elements digital signal Processing , Continuous time and discrete time signals  , Sampling Theorem  , Discrete time signals , Discrete time systems , Z transform  , Convolution and correlation.


 

Part 1 : Video 


Part 2 : Video




Concepts Covered :

Signals ans Systems ,Elements digital signal Processing , Continuous time and discrete time signals  , Sampling Theorem  , Discrete time signals , Discrete time systems , Z transform  , Convolution and correlation. 





More aboutSignals ans Systems ,Elements digital signal Processing , Continuous time and discrete time signals , Sampling Theorem , Discrete time signals , Discrete time systems , Z transform , Convolution and correlation.

Implementation of Jury's Algorithm

Posted by fasxxzczc on Wednesday 21 March 2012

Implementation of Jury's Algorithm




1:  #include<iostream.h>  
2:  #include<conio.h>  
3:  #include<stdio.h>  
4:  #include<stdlib.h>  
5:  #include<math.h>  
6:  void main(void)  
7:  {  
8:   int b[10]={0},mat[10],num1,temp,a[5],i,j;  
9:   clrscr();  
10:   cout<<"\n\t\tImplementation of Jury's Algorithm";  
11:   cout<<"\n\tInput number of coeff for D(z)::";  
12:   cin>>num1;  
13:   cout<<"\n\tInput Values::\n";  
14:   for(i=0;i<num1;i++)  
15:   {  
16:   cout<<"\n\tb["<<i<<"]::";  
17:   cin>>b[i];  
18:   }  
19:   if(b[num1-1]<0)  
20:   {  
21:       cout<<"System Unstable";  
22:       getch();  
23:       exit(0);  
24:   }  
25:   int Dz=0;  
26:   for(i=0;i<num1;i++)  
27:   Dz=Dz+pow(-1,i)*pow(-1,-i)*b[i];  
28:   if(Dz<0)  
29:   {  
30:       cout<<"System Unstable";  
31:       getch();  
32:       exit(0);  
33:   }  
34:   temp=num1-1;  
35:   for(i=0;i<(num1-3);i++)  
36:   {  
37:   if(b[0]<b[temp])  
38:   {  
39:       cout<<"\n\tSystem Unstable";  
40:       getch();  
41:       exit(0);  
42:   }  
43:   for(j=0;j<=temp;j++)  
44:    mat[j]=b[0]*b[j]-b[temp]*b[-j+temp];  
45:   temp--;  
46:   for(j=0;j<=temp;j++)  
47:    b[j]=mat[j];  
48:   }  
49:   if(b[0]<b[temp])  
50:   {  
51:       cout<<"\n\tSystem Unstable";  
52:       getch();  
53:       exit(0);  
54:   }  
55:   cout<<"\n\tSystem Stable";  
56:   getch();  
57:  }  
More aboutImplementation of Jury's Algorithm

Implementation of General Diffrence Equation

Posted by fasxxzczc

  Implementation of General Diffrence Equation

Find the output of a system described by given difference equation and initial conditions for
given input sequence. (Solution of difference equation) (Obtain the response for different
systems by changing Degree of difference equation (N) and coefficients and also for
different input sequence x(n). Observe the response by considering system as FIR and IIR
system) .

1:  #include<iostream.h>  
2:  #include<stdio.h>  
3:  #include<conio.h>  
4:  #include<math.h>  
5:  void main(void)  
6:  {  
7:   float a[10],b[10],x[20],y[20],sumx,sumy;  
8:   int N,M,k,L,n;  
9:   clrscr();  
10:   cout<<"\tImplementation of General Diffrence Equation";  
11:   cout<<"\n\n\tEnter Number of Coefficients a[k]::";  
12:   cin>>N;  
13:   cout<<"\tInput Values::";  
14:   for(k=1;k<=N;k++)  
15:   {  
16:   cout<<"\n\ta["<<k<<"]::";  
17:   cin>>a[k];  
18:   }  
19:   cout<<"\n\n\tEnter Number of Coefficients b[k]::";  
20:   cin>>M;  
21:   cout<<"\tInput Values::";  
22:   for(k=0;k<M;k++)  
23:   {  
24:   cout<<"\n\tb["<<k<<"]::";  
25:   cin>>b[k];  
26:   }  
27:   cout<<"\n\n\tEnter Number of Samples x[n]::";  
28:   cin>>L;  
29:   cout<<"\tInput Values::";  
30:   for(k=0;k<L;k++)  
31:   {  
32:   cout<<"\n\tx["<<k<<"]::";  
33:   cin>>x[k];  
34:   }  
35:   for(n=0;n<L;n++)  
36:   {  
37:   sumx=sumy=0.0;  
38:   for(k=1;(k<=N)&&(k<=n);k++)  
39:    sumy+=a[k]*y[n-k];  
40:   for(k=0;(k<M)&&(k<=n);k++)  
41:    sumx+=b[k]*x[n-k];  
42:   y[n]=sumx-sumy;  
43:   cout<<"\n\ty["<<n<<"]::"<<y[n];  
44:   }  
45:   getch();  
46:  }  

More aboutImplementation of General Diffrence Equation

Circular Convolution of two sequences using DFT and IDFT

Posted by fasxxzczc

Circular Convolution of  two sequences using DFT and IDFT

Compute the circular convolution of given two sequences using DFT and IDFT.





1:  #include<graphics.h>  
2:  #include<iostream.h>  
3:  #include<conio.h>  
4:  #include<stdlib.h>  
5:  void main(void)  
6:  {  
7:   int sample,impulse,sam[10],imp[10],out[10][10],outp[10]={0},i;  
8:   int gd=DETECT,gm,maxx,maxy,j,k;  
9:   char str[5];  
10:   initgraph(&gd,&gm,"c:\\tc\\bgi");  
11:   maxx=getmaxx();   // Returns maximum x or y screen coordinate  
12:   maxy=getmaxy();  
13:   cout<<"\n\tEnter the number of element in sample sequence::";  
14:   cin>>sample;  
15:   cout<<"\n\tEnter the number of element in impulse sequence::";  
16:   cin>>impulse;           //input impulse & sample sequence  
17:   cout<<"\n\tEnter the sample sequence";  
18:   for(i=0;i<sample;i++)  
19:   cin>>sam[i];  
20:   cout<<"\n\tEnter the impusle sequence";  
21:   for(i=0;i<impulse;i++)  
22:   cin>>imp[i];  
23:   if(sample<impulse)  
24:   for(i=sample;i<impulse;i++)  
25:    sam[i]=0;  
26:   else  
27:   for(i=impulse;i<sample;i++)  
28:    imp[i]=0;  
29:   if(sample<impulse)  
30:        sample=impulse;  
31:   int temp;  
32:   for(i=0;i<sample;i++)  
33:       for(j=0;j<sample;j++)  
34:       {  
35:            out[(j+i)%sample][i]=sam[j];  
36:       }  
37:   for(j=0;j<sample;j++)  
38:    for(k=0;k<sample;k++)  
39:     outp[j]=outp[j]+out[j][k]*imp[k];  
40:   int samp=sample;  
41:   setcolor(RED);  
42:   line(0,maxy/2,maxx,maxy/2);  
43:   line(maxx/2,0,maxx/2,maxy);  
44:   setcolor(GREEN);  
45:   for(i=0;i<samp;i++)  
46:   {  
47:    line(maxx/2+i*30,maxy/2,maxx/2+i*30,maxy/2-outp[i]*5);  
48:    moveto(maxx/2+i*30,maxy/2-outp[i]*5-10);  
49:    itoa(outp[i],str,10);        //converts integer to string  
50:    outtext(str);  
51:   }  
52:   getch();  
53:  }  
More aboutCircular Convolution of two sequences using DFT and IDFT

N Point Circular Convolution of sequences

Posted by fasxxzczc

 N Point Circular Convolution of  sequences

Problem Statement : Find the N point circular convolution of given two sequences. Test it for linear convolution





1:  #include<graphics.h>  
2:  #include<iostream.h>  
3:  #include<conio.h>  
4:  #include<stdlib.h>  
5:  void main(void)  
6:  {  
7:   int sample,impulse,sam[10],imp[10],out[10][10],outp[10]={0},i;  
8:   int gd=DETECT,gm,maxx,maxy,j;  
9:   char str[5];  
10:   initgraph(&gd,&gm,"c:\\tc\\bgi");  
11:   maxx=getmaxx();   // Returns maximum x or y screen coordinate  
12:   maxy=getmaxy();  
13:   cout<<"\n\tEnter the number of element in sample sequence::";  
14:   cin>>sample;  
15:   cout<<"\n\tEnter the number of element in impulse sequence::";  
16:   cin>>impulse;           //input impulse & sample sequence  
17:   cout<<"\n\tEnter the sample sequence";  
18:   for(i=0;i<sample;i++)  
19:   cin>>sam[i];  
20:   cout<<"\n\tEnter the impusle sequence";  
21:   for(i=0;i<impulse;i++)  
22:   cin>>imp[i];  
23:   for(i=0;i<sample;i++)  
24:   for(j=0;j<impulse;j++)  
25:    out[i][j]=sam[i]*imp[j];  
26:   for(i=0;i<impulse;i++)  
27:   for(j=0;j<sample;j++)  
28:    outp[j+i]=outp[j+i]+out[j][i];  
29:   int samp=i+j-1;  
30:   setcolor(RED);  
31:   line(0,maxy/2,maxx,maxy/2);  
32:   line(maxx/2,0,maxx/2,maxy);  
33:   setcolor(GREEN);  
34:   for(i=0;i<samp;i++)  
35:   {  
36:    line(maxx/2+i*30,maxy/2,maxx/2+i*30,maxy/2-outp[i]*5);  
37:    moveto(maxx/2+i*30,maxy/2-outp[i]*5-10);  
38:    itoa(outp[i],str,10);        //converts integer to string  
39:    outtext(str);  
40:   }  
41:   getch();  
42:  }  

Using Graph

1:  #include<graphics.h>  
2:  #include<iostream.h>  
3:  #include<conio.h>  
4:  #include<stdlib.h>  
5:  void main(void)  
6:  {  
7:   int sample,impulse,sam[10]={0},imp[10]={0},outp[10]={0},i;  
8:   int gd=DETECT,gm,maxx,maxy,j,k,sum;  
9:   char str[5];  
10:   initgraph(&gd,&gm,"e:\\tc\\bgi");  
11:   maxx=getmaxx();   // Returns maximum x or y screen coordinate  
12:   maxy=getmaxy();  
13:   cout<<"\n\tEnter the number of element in sample sequence::";  
14:   cin>>sample;  
15:   cout<<"\n\tEnter the number of element in impulse sequence::";  
16:   cin>>impulse;           //input impulse & sample sequence  
17:   cout<<"\n\tEnter the sample sequence";  
18:   for(i=0;i<sample;i++)  
19:   cin>>sam[i];  
20:   cout<<"\n\tEnter the impusle sequence";  
21:   for(i=0;i<impulse;i++)  
22:   cin>>imp[i];  
23:   for(k=0;k<(sample+impulse-1);k++)  
24:   {  
25:   cleardevice();  
26:   setcolor(MAGENTA);  
27:   outtextxy(maxx/2+40,0,"Sample Sequence x(n)");  
28:   outtextxy(maxx/2+40,165,"Impulse Response h(-n+k)");  
29:   outtextxy(maxx/2+40,330,"x(k)*h(-k+n)");  
30:   setcolor(RED);  
31:   line(maxx/2,0,maxx/2,maxy);  
32:   line(0,maxy/6,maxx,maxy/6);  
33:   line(0,maxy/2,maxx,maxy/2);  
34:   line(0,5*maxy/6,maxx,5*maxy/6);  
35:   setlinestyle(DOTTED_LINE,1,1);  
36:   setcolor(GREEN);  
37:   line(0,maxy/3,maxx,maxy/3);  
38:   line(0,2*maxy/3,maxx,2*maxy/3);  
39:   setlinestyle(SOLID_LINE,1,3);  
40:   for(i=0;i<sample;i++)  
41:   {  
42:    line(maxx/2+i*30,maxy/6,maxx/2+i*30,maxy/6-sam[i]*2);  
43:    if(sam[i]>=0)  
44:        moveto(maxx/2+i*30,maxy/6-sam[i]*2-10);  
45:    else  
46:         moveto(maxx/2+i*30,maxy/6-sam[i]*2+10);  
47:    itoa(sam[i],str,10);        //converts integer to string  
48:    outtext(str);  
49:   }  
50:   for(i=impulse-1;i>=0;i--)  
51:   {  
52:    line(maxx/2-(i-k)*30,maxy/2,maxx/2-(i-k)*30,maxy/2-imp[i]*2);  
53:    if(imp[i]>=0)  
54:        moveto(maxx/2-(i-k)*30,maxy/2-imp[i]*2-10);  
55:    else  
56:         moveto(maxx/2-(i-k)*30,maxy/2-imp[i]*2+10);  
57:    itoa(imp[i],str,10);        //converts integer to string  
58:    outtext(str);  
59:   }  
60:   int temp=k;  
61:   sum=0;  
62:   for(i=k;i>=0;i--)  
63:   {  
64:    sum+=sam[i]*imp[temp-i];  
65:    line(maxx/2+i*30,5*maxy/6,maxx/2+i*30,5*maxy/6-sam[i]*imp[temp-i]*2);  
66:    if(outp[i]>=0)  
67:        moveto(maxx/2+i*30,5*maxy/6-sam[i]*imp[temp-i]*2-10);  
68:    else  
69:         moveto(maxx/2+i*30,5*maxy/6-sam[i]*imp[temp-i]*2+10);  
70:    itoa(sam[i]*imp[temp-i],str,10);        //converts integer to string  
71:    outtext(str);  
72:   }  
73:   outp[k]=sum;  
74:   outtextxy(330,maxy-10,"y(");  
75:   itoa(k,str,10);        //converts integer to string  
76:   outtextxy(330+15,maxy-10,str);  
77:   outtextxy(330+30,maxy-10,")::");  
78:   itoa(outp[k],str,10);        //converts integer to string  
79:   outtextxy(390,maxy-10,str);  
80:   setcolor(YELLOW);  
81:   outtextxy(20,maxy-10,"Press Any Key to Continue::");  
82:   getch();  
83:   }  
84:   cleardevice();  
85:   outtextxy(maxx/2+20,20,"Output y(n)");  
86:   setcolor(RED);  
87:   setlinestyle(SOLID_LINE,1,1);  
88:   line(maxx/2,0,maxx/2,maxy);  
89:   line(0,maxy/2,maxx,maxy/2);  
90:   setcolor(GREEN);  
91:   setlinestyle(SOLID_LINE,1,3);  
92:   for(i=0;i<(sample+impulse-1);i++)  
93:   {  
94:    line(maxx/2+i*30,maxy/2,maxx/2+i*30,maxy/2-outp[i]*2);  
95:    if(sam[i]>=0)  
96:        moveto(maxx/2+i*30,maxy/2-outp[i]*2-10);  
97:    else  
98:         moveto(maxx/2+i*30,maxy/2-outp[i]*2+10);  
99:    itoa(outp[i],str,10);        //converts integer to string  
100:    outtext(str);  
101:   }  
102:   getch();  
103:   closegraph();  
104:  }  


More aboutN Point Circular Convolution of sequences

N point DFT or IDFT of sequence

Posted by fasxxzczc

N point DFT  or IDFT of  sequence


Problem Statement :Find the N point DFT / IDFT of the given sequence x (n) .Plot the magnitude spectrum|X(K)| Vs K. (Analyze the output for different N and the same input sequence x(n). Also observe the periodicity and symmetry property) .


1:  #include<stdio.h>  
2:  #include<conio.h>  
3:  #include<complex.h>  
4:  void main()  
5:  {  
6:     float x[20],pi=22.0/7.0;  
7:     complex X[20];  
8:     int k,n,N;  
9:     clrscr();  
10:     printf("\t\t\tDFT Fourier Transform\n");  
11:     printf("\nEnter the number samples in the sequence x(n), N = ");  
12:     scanf("%d",&N);  
13:     printf("\nEnter the samples of sequence x(n)\n");  
14:     for(n = 0; n < N; n++)  
15:     {  
16:       printf("x(%d) = ",n);  
17:       scanf("%f",&x[n]);  
18:     }  
19:     for(k = 0; k < N; k++)  
20:     {  
21:       X[k]=complex(0.0,0.0);  
22:       for(n = 0; n < N; n++)  
23:       {  
24:        complex temp=complex(0.0,-2*pi*k*n/N);  
25:        X[k] = X[k] + x[n]*exp(temp);  
26:       }  
27:     }  
28:     printf("\nThe %d point DFT of given sequence is...",N);  
29:     printf("\n\tReal X(k)\t\tImaginary X(k)");  
30:     for(k = 0; k < N; k++)  
31:      printf("\nX(%d) = %3.6f\t\t %3.4f",k,real(X[k]),imag(X[k]));  
32:     getch();  
33:  }  
More aboutN point DFT or IDFT of sequence

N-Point FFT Algorithm to find DFT or IDFT

Posted by fasxxzczc

N-Point FFT Algorithm to find DFT or IDFT


Problem Statement : Implement the N-point radix-2 DIT or DIF FFT algorithm to find DFT or IDFT of given sequence x (n). (Analyze the output for different N Program should work for any value of N (generalized)) .



1:  #include<conio.h>  
2:  #include<stdio.h>  
3:  #include<complex.h>  
4:  #include<stdlib.h>  
5:  complex data[64];  
6:  void main()  
7:  {  
8:     int ind(int n,int i);  
9:     void split(int N,int n);  
10:     double x,y;  
11:     int N,n,i,j,k,ch;  
12:     clrscr();  
13:     cout<<"    Radix-2 DIT FFT algorithm FOR DFT & IDFT\n\n";  
14:     cout<<"Enter the number of samples in the sequence x(n), N = ";  
15:     cin>>N;           // number of samples in x(n)  
16:     cout<<"\nEnter the samples of sequence x(n)";  
17:     for(n=0;n<N;n++)  
18:     {  
19:      cout<<"\nReal x("<<n<<") = ";    // enter values of samples of x(n)  
20:      cin>>x;  
21:      cout<<"Imag x("<<n<<") = ";    // enter values of samples of x(n)  
22:      cin>>y;  
23:      data[n]=complex(x,y);  
24:     }  
25:     cout<<"\n\t1.DFT\n\t2.IDFT\n\t3.EXIT\n\n\tEnter Ur Choice::";  
26:     cin>>ch;  
27:     switch(ch)  
28:     {  
29:     case 1:  
30:          n=log(N)/log(2);  
31:          split(N,n);  
32:          i=0;  
33:          while(i!=n)  
34:          {  
35:          int p1=pow(2,i),p2=pow(2,i+1),h=(N/p2);  
36:          for(j=0;j<h;j++)  
37:          {  
38:            for(k=0;k<p1;k++)  
39:            {  
40:             complex temp,temp1,temp2;  
41:             temp=complex(0.0,-(44.0*k)/(7.0*p2));  
42:             temp=exp(temp);  
43:             temp1=data[p2*j+k]+temp*data[p2*j+k+p1];  
44:             temp2=data[p2*j+k]-temp*data[p2*j+k+p1];  
45:             data[p2*j+k]=temp1;  
46:             data[p2*j+k+p1]=temp2;  
47:            }  
48:          }  
49:          i++;  
50:          }  
51:          break;  
52:     case 2:  
53:          n=log(N)/log(2);  
54:          i=n-1;  
55:          while(i>=0)  
56:          {  
57:          int p1=pow(2,i),p2=pow(2,i+1),h=(N/p2);  
58:          for(j=0;j<h;j++)  
59:          {  
60:            for(k=0;k<p1;k++)  
61:            {  
62:             complex temp,temp1,temp2;  
63:             temp=complex(0.0,(44.0*k)/(7.0*p2));  
64:             temp=exp(temp);  
65:             temp1=(data[p2*j+k]+data[p2*j+k+p1]);  
66:             temp2=((data[p2*j+k]-data[p2*j+k+p1])*temp);  
67:             if(i==n-1)  
68:             {  
69:             temp1=temp1/N;  
70:             temp2=temp2/N;  
71:             }  
72:             data[p2*j+k]=temp1;  
73:             data[p2*j+k+p1]=temp2;  
74:            }  
75:          }  
76:          i--;  
77:          }  
78:          split(N,n);  
79:          break;  
80:     case 3:  
81:         exit(0);  
82:     }  
83:     clrscr();  
84:     cout<<"\nReal(z)";  
85:     gotoxy(30,2);  
86:     cout<<"Imag(z)\n";  
87:     for(i=0;i<N;i++)  
88:     {  
89:     printf("%1.2lf",real(data[i]));  
90:     gotoxy(30,3+i);  
91:     printf("%1.2lf\n",imag(data[i]));  
92:     }  
93:     getch();  
94:  }  
95:  int ind(int i,int n)  
96:  {  
97:   int j,temp,num=0;  
98:   for(j=0;j<n;j++)  
99:   {  
100:   temp=i&(int)(pow(2,j));  
101:   if(temp!=0)  
102:    num+=pow(2,n-j-1);  
103:   }  
104:   return num;  
105:  }  
106:  void split(int N,int n)  
107:  {  
108:     int index,i;  
109:     complex temp;  
110:     for(i=0;i<N;i++)  
111:     {  
112:      index=ind(i,n);  
113:      if(index>i)  
114:      {  
115:       temp=data[i];  
116:       data[i]=data[index];  
117:       data[index]=temp;  
118:      }  
119:     }  
120:  }  
More aboutN-Point FFT Algorithm to find DFT or IDFT

Pole Zero Plot from System function H(Z) Expressed as Rational Function

Posted by fasxxzczc

Pole Zero Plot from  System function H(Z) Expressed as Rational Function


Problem Statement :Draw a pole zero plot from a given system function H(Z) expressed as rational function. (Display pole zero table and pole zero plot) .



1:  #include<iostream.h>  
2:  #include<conio.h>  
3:  #include<stdio.h>  
4:  void main(void)  
5:  {  
6:   int pol[5]={0},zer[5]={0},num1,num2,a[6],b[6],i;  
7:   clrscr();  
8:   cout<<"\n\tInput number of poles for x(n)(MAX 5)::";  
9:   cin>>num1;  
10:   cout<<"\n\tInput Values::\n";  
11:   for(i=1;i<=num1;i++)  
12:   {  
13:   cout<<"\n\tp["<<i<<"]::";  
14:   cin>>pol[i];  
15:   }  
16:   cout<<"\n\tInput number of zeros for x(n)(MAX 5)::";  
17:   cin>>num2;  
18:   cout<<"\n\tInput Values::\n";  
19:   for(i=1;i<=num2;i++)  
20:   {  
21:   cout<<"\n\tz["<<i<<"]::";  
22:   cin>>zer[i];  
23:   }  
24:   a[0]=b[0]=1;  
25:   a[1]=-(pol[1]+pol[2]+pol[3]+pol[4]+pol[5]);  
26:   a[2]=pol[1]*(pol[2]+pol[3]+pol[4]+pol[5])+pol[2]*(pol[3]+pol[4]+pol[5])  
27:     +pol[3]*(pol[4]+pol[5])+pol[4]*pol[5];  
28:   a[3]=-(pol[1]*pol[2]*(pol[3]+pol[4]+pol[5])+pol[2]*pol[3]*(pol[4]+pol[5])  
29:     +pol[4]*pol[5]*(pol[1]+pol[2]+pol[3])+pol[1]*pol[3]*(pol[4]+pol[5]));  
30:   a[4]=pol[1]*pol[2]*pol[3]*(pol[4]+pol[5])+pol[3]*pol[4]*pol[5]*(pol[1]+  
31:     pol[2])+pol[1]*pol[2]*pol[4]*pol[5];  
32:   a[5]=-(pol[1]*pol[2]*pol[3]*pol[4]*pol[5]);  
33:   b[1]=-(zer[1]+zer[2]+zer[3]+zer[4]+zer[5]);  
34:   b[2]=zer[1]*(zer[2]+zer[3]+zer[4]+zer[5])+zer[2]*(zer[3]+zer[4]+zer[5])  
35:     +zer[3]*(zer[4]+zer[5])+zer[4]*zer[5];  
36:   b[3]=-(zer[1]*zer[2]*(zer[3]+zer[4]+zer[5])+zer[2]*zer[3]*(zer[4]+zer[5])  
37:     +zer[4]*zer[5]*(zer[1]+zer[2]+zer[3])+zer[1]*zer[3]*(zer[4]+zer[5]));  
38:   b[4]=zer[1]*zer[2]*zer[3]*(zer[4]+zer[5])+zer[3]*zer[4]*zer[5]*(zer[1]+  
39:     zer[2])+zer[1]*zer[2]*zer[4]*zer[5];  
40:   b[5]=-(zer[1]*zer[2]*zer[3]*zer[4]*zer[5]);  
41:   cout<<"\n\nCoefficient for x(n)::";  
42:   for(i=0;i<=num1;i++)  
43:       cout<<b[i]<<",";  
44:   cout<<"\b ";  
45:   cout<<"\n\nCoefficient for y(n)::";  
46:   for(i=0;i<=num2;i++)  
47:       cout<<a[i]<<",";  
48:   cout<<"\b ";  
49:   getch();  
50:  }  
More aboutPole Zero Plot from System function H(Z) Expressed as Rational Function

Magnitude and Phase Response of System

Posted by fasxxzczc

Magnitude and Phase Response of  System


Problem Statement : Write a C program to plot the magnitude and phase response of a given system ( given: h(n): impulse response of system S) (Observe the frequency response for different systems. Compare the frequency response of a system (filter) for different length h(n) i.e filter coefficients).

1:  #include<stdio.h>  
2:  #include<conio.h>  
3:  #include<math.h>  
4:  #include<graphics.h>  
5:  void main()  
6:  {  
7:    double RealNum,ImagNum,RealDen,ImagDen,Real,Imag;  
8:    double mag[640],phase[640],pi,w,wStep;  
9:    float static a[10],b[10];  
10:    int M,N,i,k,gd=DETECT,gm;  
11:    clrscr();  
12:    printf("  \nThis program displays the magnitude and phase"  
13:         " transfer function plots\nfrom given coefficients of"  
14:         " difference equation \n\n");  
15:    printf("\nenter the number of coefficients of x(n), M = ");  
16:    scanf("%d",&M);  
17:    for(i = 0; i < M; i++)  
18:    {  
19:      printf("b%d = ",i);  
20:      scanf("%f",&b[i]);  
21:    }  
22:    printf("\nenter the number of coefficients of y(n), N = ");  
23:    scanf("%d",&N);  
24:    a[0] = 1.0;  
25:    for(i = 1; i <= N; i++)  
26:    {  
27:       printf("a%d = ",i);  
28:       scanf("%f",&a[i]);  
29:    }  
30:    pi = 22.0/7.0;  
31:    wStep = pi/640.0;  
32:    w=0;  
33:    for(k = 0; k <=640; k++)  
34:    {  
35:     RealNum = b[0];  
36:     ImagNum = 0;  
37:     for(i = 1; i < M; i++)  
38:     {  
39:        RealNum = RealNum + b[i]*cos(i*w);  
40:        ImagNum = ImagNum + b[i]*sin(i*w);  
41:     }  
42:     ImagNum = ImagNum * (-1.0);  
43:     RealDen = 0;  
44:     ImagDen = 0;  
45:     for(i = 0; i <= N; i++)  
46:     {  
47:        RealDen = RealDen + a[i]*cos(i*w);  
48:        ImagDen = ImagDen + a[i]*sin(i*w);  
49:     }  
50:     ImagDen = ImagDen * (-1.0);  
51:     mag[k] = 20*log10(sqrt(RealNum*RealNum + ImagNum*ImagNum)/  
52:               sqrt(RealDen*RealDen + ImagDen*ImagDen));  
53:     phase[k]=(180.0*7.0*(atan(ImagNum/RealNum)-atan(ImagDen/RealDen)))/22.0;  
54:     w = w + wStep;  
55:    }  
56:    initgraph(&gd,&gm,"e:\\tc\\bgi");  
57:    cleardevice();  
58:    setlinestyle(DOTTED_LINE,1,1);  
59:    line(0,150,640,150);  
60:    line(0,350,640,350);  
61:    line(10,0,10,350);  
62:    for(k = 0;k<640;k++)  
63:    {  
64:       putpixel(k,-mag[k]*2+150,WHITE);  
65:       putpixel(k,-phase[k]+350,WHITE);  
66:    }  
67:    outtextxy(500,200,"Magnitude plot");  
68:    outtextxy(500,450,"Phase plot");  
69:    getch();  
70:    closegraph();  
71:  }  
More aboutMagnitude and Phase Response of System

FIR filter LPF, HPF, BPF using Windowing Method

Posted by fasxxzczc

FIR filter  LPF, HPF, BPF using Windowing Method

Problem Statement : Design an FIR filter from given specifications using windowing method ( Program should work for different types of filter specifications i.e LPF, HPF, BPF etc and all window sequences. Plot the frequency response for different frequency terms i.e. analog and DT frequency).

1:       // FIR  
2:  #include<stdio.h>  
3:  #include<conio.h>  
4:  #include<math.h>  
5:  void main()  
6:  {  
7:     float wc,tou,M,hd[50],h[50],wn,pi,n;  
8:     int choice,p;  
9:     char HPF;  
10:     clrscr();  
11:     printf("\t\tFIR filter design using windows\n\n");  
12:     printf("Enter the length (number of coefficients) of the filter M = ");  
13:     scanf("%f",&M);             // length(M) of the filter  
14:     p = (int)M;  
15:     printf("\nEnter the discrete time cutoff frequency wc = ");  
16:     scanf("%f",&wc);     // cutoff frequency of the filter i.e. wc  
17:     printf("\nif you want highpass filter, enter HPF = y, otherwise "  
18:              "perss any key\ndefault is lowpass filter\nHPF = ");  
19:     HPF = getch(); printf("%c",HPF);      // enter for HPF or LPF  
20:     tou = (M-1)/2;                  // delay in hd(n)  
21:     pi = 22.0/7.0;                   // value of pi  
22:  //  Next part of the program calculates hd(n)  
23:     for(n = 0; n <= M-1; n++)  // this loop calculates hd(n) for LPF  
24:     {              //            (by default)  
25:      hd[n] = (sin(wc*(n-tou)))/(pi*(n-tou));     // hd(n) for LPF  
26:      if((n==tou)&&((p/2)*2 != p)) hd[n] = wc/pi; // hd(n) at n = tou  
27:     }  
28:     if(HPF =='y')   // this loop recalculates hd(n) for HPF if user  
29:     {         //             wants to design HPF  
30:      for(n = 0; n <= M-1; n++)  
31:      {                        // hd(n) for HPF  
32:        hd[n] = (sin(pi*(n-tou)) - sin(wc*(n-tou)))/(pi*(n-tou));  
33:        if((n==tou)&&((p/2)*2 != p)) hd[n] = 1-(wc/pi);  
34:      }                      // hd(n) at n = tou  
35:     }  
36:  //  Next part of the program performs windowing depending upon  
37:  //                           choice of window  
38:     printf("\n\nEnter the window you want to use");// choice of window  
39:     printf("\nrectangular window (Enter 1)");      //rectangular  
40:     printf("\ntriangular(bartlett) window (Enter 2)");  //triangular  
41:     printf("\nhamming window (Enter 3)");          //hamming  
42:     printf("\nhanning window (Enter 4)\nchoice = ");     //hanning  
43:     scanf("%d",&choice);                // enter choice  
44:     switch(choice)  
45:     {       // h(n) = hd(n) * w(n) depending upon type of window  
46:      case 1 : for(n = 0; n <= M-1; n++)        // rectangular  
47:            {  
48:             wn = 1;          //wn for rectangular window  
49:             h[n] = hd[n] * wn;       // windowing operation  
50:            } break;  
51:      case 2 : for(n = 0; n <= M-1; n++)         // triangular  
52:            {  
53:             wn = 1 - (2*abs(n-tou)/(M-1));  // calculation of wn  
54:             h[n] = hd[n] * wn;       // windowing operation  
55:            } break;  
56:      case 3 : for(n = 0; n <= M-1; n++)          // hamming  
57:            {  
58:             wn = 0.54 - 0.46*cos((2*pi*n)/(M-1));      // wn  
59:             h[n] = hd[n] * wn;       // windowing operation  
60:            } break;  
61:      case 4 : for(n = 0; n <= M-1; n++)          // hanning  
62:            {  
63:             wn = (1-cos((2*pi*n)/(M-1)))/2; // calculation of wn  
64:             h[n] = hd[n] * wn;       // windowing operation  
65:            } break;  
66:     }  
67:  //  Next part of the program displays coefficients on the screen  
68:     if(HPF == 'y') printf("\ncoefficients of highpass FIR filter"  
69:                                 " are as follows...");  
70:     else printf("\ncoefficients of lowpass FIR filter"  
71:                                 " are as follows...");  
72:     for(n = 0; n <= M-1; n++)  
73:     {  
74:      printf("\nh%1.0f = %f",n,h[n]);  
75:     }  
76:       getch();  
77:  }  


More aboutFIR filter LPF, HPF, BPF using Windowing Method

IIR Filter using Bilinear Transformation

Posted by fasxxzczc

 IIR Filter  using Bilinear Transformation

Problem Statement :Design of IIR filter for given specifications using Bilinear Transformation. (Programshouldwork for different types of filter specifications i.e LPF, HPF, BPF etc and for different
transfer functions of an analog filter).


1:                 // biliner.cpp  
2:  #include<stdio.h>  
3:  #include<conio.h>  
4:  #include<math.h>  
5:  void main()  
6:  {  
7:     float B[20],b[20][3],a[20][3],pReal,pImag;  
8:     float wc,N,pi,Theta,omegaC,den;  
9:     int k;  
10:     clrscr();  
11:     printf("\t\tButterworth filter design using Bilinear "  
12:                                 "transformation\n\n");  
13:     printf("Enter the order of the filter N = ");  
14:     scanf("%f",&N);               // order of the filter  
15:     printf("\nEnter the cutoff frequency of digital filter wc = ");  
16:     scanf("%f",&wc);   // cutoff frequency of digital filter i.e. wc  
17:     omegaC = tan(wc/2); // cutoff frequency of equivalent analog  
18:  //              filter by bilinear frequency relationship  
19:     pi = 22.0/7.0;                   // value of pi  
20:     for(k = 0; k < N/2; k++)// loop for computation of first N/2 poles  
21:     {  
22:      Theta = ((N+2*k+1)*pi)/(2*N);       // angle of k'th pole  
23:      pReal = -1*omegaC*cos(Theta); // real part of pole made positive  
24:      pImag = omegaC*sin(Theta);       // imaginary part of pole  
25:        den = 1+2*pReal+pReal*pReal+pImag*pImag;  
26:       B[k] = (omegaC*omegaC)/den;        // calculation of Bk  
27:      b[k][0] = 1;  //|  for all the sections the value of bk0 = 1,  
28:      b[k][1] = 2;  //|      bk1 = 2 & bk2 = 1. These values are  
29:      b[k][2] = 1;  //|        fixed(see theory for details).  
30:      a[k][0] = 1;             // value of ak0 is always 1  
31:      a[k][1] = (2*(pReal*pReal+pImag*pImag)-2)/den;      // ak1  
32:      a[k][2] = (1-2*pReal+pReal*pReal+pImag*pImag)/den;    // ak2  
33:               // the above two statements calculate ak1 and ak2  
34:     }  
35:     if((N/2) != k)  
36:     {  
37:      k--;       // recompute the pole without complex conjugate  
38:      den = omegaC+1;  
39:      B[k] = omegaC/den;             // calculation of Bk  
40:      b[k][0] = 1; //|  for first order section bk0 = 1, bk1 = 1 and  
41:      b[k][1] = 1; //|     bk2 = 0 always. These values are fixed  
42:      b[k][2] = 0; //|           and need not be calculated  
43:      a[k][0] = 1;             // value of ak0 is always 1  
44:      a[k][1] = (omegaC-1)/den;         // calculation of ak1  
45:      a[k][2] = 0;     // ak2 is always 0 for first order section  
46:     }  
47:     printf("\nThe coefficients of cascaded second order sections "  
48:                    "of digital\nfilter are as follows...\n");  
49:     for(k = 0; k < N/2; k++)  
50:     {  
51:      printf("\nB%d = %f\tb%d0 = %f\ta%d0 = %f"  
52:                            ,k,B[k],k,b[k][0],k,a[k][0]);  
53:      printf("\n\t\tb%d1 = %f\ta%d1 = %f",k,b[k][1],k,a[k][1]);  
54:      printf("\n\t\tb%d2 = %f\ta%d2 = %f\n",k,b[k][2],k,a[k][2]);  
55:     }  
56:  getch();  
57:  }  
58:  /*          Butterworth filter design using Bilinear transformation  
59:  Enter the order of the filter N = 4  
60:  Enter the cutoff frequency of digital filter wc = 100  
61:  The coefficients of cascaded second order sections of digital  
62:  filter are as follows...  
63:  B0 = 0.085426  b00 = 1.000000 a00 = 1.000000  
64:            b01 = 2.000000 a01 = -2.140140  
65:            b02 = 1.000000 a02 = 1.481843  
66:  B1 = 0.129408  b10 = 1.000000 a10 = 1.000000  
67:            b11 = 2.000000 a11 = -3.242013  
68:            b12 = 1.000000 a12 = 2.759646  
69:   */  
More aboutIIR Filter using Bilinear Transformation

Generate Waves of Sine , Cosine and Exponential Signals

Posted by fasxxzczc

Generate Waves of Sine , Cosine and Exponential Signals

Problem Statement : Write a C program to generate samples of sine, Cosine and exponential signals at specified sampling frequency and signal parameters


1:  //     Generation of samples of Cosine,Sine & Exponential Waves  
2:  #include<dos.h>  
3:  #include<graphics.h>  
4:  #include<math.h>  
5:  #include<iostream.h>  
6:  #include<stdio.h>  
7:  #include<conio.h>  
8:  #include<stdlib.h>  
9:  void draw_seq(int sam,int choice)  //a is number of samples  
10:  {  
11:   int i,j,size,k;  
12:   float F,Fs,a;  
13:   setcolor(15);  
14:   line(getmaxx()/2,0,getmaxx()/2,getmaxy());   //drawing axes  
15:   line(0,getmaxy()/2,getmaxx(),getmaxy()/2);  
16:   setcolor(14);  
17:   setfillstyle(SOLID_FILL,14);  
18:   switch(choice)  
19:   {  
20:   case 1 :  
21:       outtextxy(getmaxx()-103,20,"Sine Wave");  
22:       cout<<"Input Sampling Frequency::";  
23:       cin>>Fs;  
24:       cout<<"Input Analog Frequency::";  
25:       cin>>F;  
26:       for(i=0;i<=sam;i++)  
27:       {  
28:        float x=sin(2*3.14*(F/Fs)*i);  
29:        line(getmaxx()/2+i*10,getmaxy()/2-x*30,getmaxx()/2+i*10,getmaxy()/2);  
30:        pieslice(getmaxx()/2+(i*10),getmaxy()/2-x*30,0,360,2);  
31:       }  
32:       break;  
33:   case 2 :  
34:       outtextxy(getmaxx()-103,20,"Cosine Wave");  
35:       cout<<"Input Sampling Frequency::";  
36:       cin>>Fs;  
37:       cout<<"Input Analog Frequency::";  
38:       cin>>F;  
39:       for(i=0;i<=sam;i++)  
40:       {  
41:        float x=cos(2*3.14*(F/Fs)*i);  
42:        line(getmaxx()/2+i*10,getmaxy()/2-x*30,getmaxx()/2+i*10,getmaxy()/2);  
43:        pieslice(getmaxx()/2+(i*10),getmaxy()/2-x*30,0,360,2);  
44:       }  
45:       break;  
46:   case 3 :  
47:       outtextxy(getmaxx()-123,20,"Exponential Wave");  
48:       cout<<"Input Constant k::";  
49:       cin>>k;  
50:       cout<<"Input Magnitude a::";  
51:       cin>>a;  
52:       for(i=0;i<=sam;i++)  
53:       {  
54:        float x=k*pow(a,i);  
55:        line(getmaxx()/2+i*10,getmaxy()/2-x*40,getmaxx()/2+i*10,getmaxy()/2);  
56:        pieslice(getmaxx()/2+(i*10),getmaxy()/2-x*40,0,360,2);  
57:       }  
58:       break;  
59:   }  
60:   getch();  
61:  }  
62:  void main(void)  
63:  {  
64:   int gd=DETECT,gm;  
65:   int sample,choice;  
66:   while(1)  
67:   {  
68:   initgraph(&gd,&gm,"e:\\tc\\bgi");  
69:   cleardevice();  
70:   cout<<"\n\t\tGeneration of Standard Sequences\n\t1.Sine Wave";  
71:   cout<<"\n\t2.Cosine Wave\n\t3.Exponential\n\t4.Exit";  
72:   setcolor(GREEN);  
73:   outtextxy(10,100,"Enter Ur Choice :");  
74:   gotoxy(32,7);  
75:   cin>>choice;  
76:   if(choice==4)  
77:       exit(0);  
78:   setcolor(GREEN);  
79:   outtextxy(10,120,"Enter Number of SAMPLE :");  
80:   gotoxy(32,8);  
81:   cin>>sample;  
82:   if(sample==0)  
83:   {     setcolor(14);  
84:       outtextxy(getmaxx()/2-150,getmaxy()/2-10,"No Graph Exists for ZERO Samples");  
85:   }  
86:   switch(choice)  
87:   {  
88:    case 1:  
89:       draw_seq(sample,1);  
90:       break;  
91:    case 2:  
92:       draw_seq(sample,2);  
93:       break;  
94:    case 3:  
95:       draw_seq(sample,3);  
96:       break;  
97:   }  
98:   }  
99:  }  
More aboutGenerate Waves of Sine , Cosine and Exponential Signals

Input Sequence using Linear Convolution

Posted by fasxxzczc

 Output of  Input Sequence using Linear Convolution

Problem Statement :  Find the output of a given system for given input sequence using linear convolution

1:  //     Generation of Standard Sequences (Unit Sample, Unit Ramp, Unit Step)  
2:  #include<dos.h>  
3:  #include<graphics.h>  
4:  #include<math.h>  
5:  #include<iostream.h>  
6:  #include<stdio.h>  
7:  #include<conio.h>  
8:  #include<stdlib.h>  
9:  void draw_seq(int a,int choice)  //a is number of samples  
10:  {  
11:       int i,j,size;  
12:       size = getmaxx()/(2*a);  
13:       setcolor(15);  
14:       line(getmaxx()/2,0,getmaxx()/2,getmaxy());   //drawing axes  
15:       line(0,getmaxy()/2,getmaxx(),getmaxy()/2);  
16:       setcolor(14);  
17:       setfillstyle(SOLID_FILL,14);  
18:       for(i=-a;i<0;i++)               //     left part of origin  
19:            pieslice(getmaxx()/2+(i*size),getmaxy()/2,0,360,2);  
20:       switch(choice)  
21:       {  
22:            case 1 :  
23:                 outtextxy(getmaxx()/2-43,20,"UNIT - SAMPLE");  
24:                 for(i=0;i<=a;i++)  
25:                 {  
26:                      if(i==0)  
27:                      {  
28:                           pieslice(getmaxx()/2,getmaxy()/2-size,0,360,2);  
29:                           line(getmaxx()/2,getmaxy()/2-size,getmaxx()/2,getmaxy()/2);  
30:                      }  
31:                      else  
32:                           pieslice(getmaxx()/2+(i*size),getmaxy()/2,0,360,2);  
33:                 }  
34:                 break;  
35:            case 2 :  
36:                 outtextxy(getmaxx()/2-43,20,"UNIT - STEP");  
37:                 for(i=0;i<=a;i++)  
38:                 {  
39:                      pieslice(getmaxx()/2+(i*size),getmaxy()/2-size,0,360,2);  
40:                      line(getmaxx()/2+(i*size),getmaxy()/2,getmaxx()/2+(i*size),getmaxy()/2-size);  
41:                 }  
42:                 break;  
43:            case 3 :  
44:                 outtextxy(getmaxx()/2-43,20,"UNIT - RAMP");  
45:                 for(i=0;i<=a;i++)  
46:                 {    setfillstyle(SOLID_FILL,14);  
47:                      pieslice(getmaxx()/2+(i*size),getmaxy()/2-size-((i-1)*size),0,360,2);  
48:                      line(getmaxx()/2+(i*size),getmaxy()/2,getmaxx()/2+(i*size),getmaxy()/2-size-((i-1)*size));  
49:                 }  
50:                 break;  
51:       }  
52:       getch();  
53:  }  
54:  void main()  
55:  {  
56:       int gd=DETECT,gm;  
57:       int sample,choice;  
58:       while(1)  
59:       {  
60:       initgraph(&gd,&gm,"E:\\tc\\bgi");  
61:       cleardevice();  
62:       cout<<"\n\t\tGeneration of Standard Sequences\n\t1.Unit Sample";  
63:       cout<<"\n\t2.Unit Step\n\t3.Unit Ramp\n\t4.Exit";  
64:       setcolor(GREEN);  
65:       outtextxy(10,100,"Enter Ur Choice :");  
66:       gotoxy(32,7);  
67:       cin>>choice;  
68:       if(choice==4)  
69:            exit(0);  
70:       setcolor(GREEN);  
71:       outtextxy(10,120,"Enter Number of SAMPLE :");  
72:       gotoxy(32,8);  
73:       cin>>sample;  
74:       if(sample==0)  
75:       {     setcolor(14);  
76:            outtextxy(getmaxx()/2-150,getmaxy()/2-10,"No Graph Exists for ZERO Samples");  
77:       }  
78:       switch(choice)  
79:       {  
80:        case 1:  
81:            draw_seq(sample,1);  
82:            break;  
83:        case 2:  
84:            draw_seq(sample,2);  
85:            break;  
86:        case 3:  
87:            draw_seq(sample,3);  
88:            break;  
89:       }  
90:      }  
91:  }  
More aboutInput Sequence using Linear Convolution

Digital Signal Processing Syllabus

Posted by fasxxzczc

                                                       DIGITAL SIGNAL PROCESSING


Digital  Signal Processing


Objectives:

· To learn methodology to analyze signals and systems
· Study transformed domain representation of signals and systems
· Design of filters as DT systems
· To get acquainted with the DSP Processors and DSP applications

Signals and Systems

Continuous time (CT), Discrete-time (DT) and Digital signals, Basic DT signals and
Operations. Discrete-time Systems, Properties of DT Systems and Classification, Linear Time
Invariant (LTI) Systems, Impulse response, Linear convolution, Linear constant coefficient
difference equations, FIR and IIR systems, Periodic Sampling, Relationship between Analog
and DT frequencies, Aliasing, Sampling Theorem, A to D conversion Process: Sampling,
quantization and encoding. 

Frequency Domain Representation of Signal

Introduction to Fourier Series, Representation of DT signal by Fourier Transform (FT),
Properties of FT: Linearity, periodicity, time shifting, frequency shifting, time reversal,
differentiation, convolution theorem, windowing theorem .Discrete Fourier Transform (DFT),
DFT and FT, IDFT, Twiddle factor, DFT as linear transformation matrix, Properties of DFT,
circular shifting, Circular Convolution, DFT as Linear filtering, overlap save and add, DFT
spectral leakage 

Fast Fourier Transform (FFT) and Z-Transform (ZT)

Effective computation of DFT, Radix-2 FFT algorithms: DIT FFT, DIF FFT, Inverse DFT
using FFT, Z-transform (ZT) , ZT & FT, ZT &DFT , ROC and its properties, ZT Properties ,
Rational ZT, Pole Zero Plot, Behaviour of causal DT signals, Inverse Z Transform (IZT): power
series method, partial fraction expansion (PFE) , Residue method. 

Analysis of DT - LTI Systems:

System function H(z), H(z) in terms of Nth order general difference equation, all poll and all
zero systems, Analysis of LTI system using H(Z), Unilateral Z-transform: solution of difference
equation, Impulse and Step response from difference equation, Pole zero plot of H(Z) and
difference equation, Frequency response of system, Frequency response from pole-zero plot
using simple geometric construction, Ideal frequency selective filters, magnitude and phase
response 

Digital Filter Design

Concept of filtering, Ideal filters and approximations, specifications, FIR and IIR filters, linear
phase response, FIR filter Design: Fourier Series method, Windowing method, Gibbs
Phenomenon, desirable features of windows, Different window sequences and its analysis,
Design examples:
IIR filter design: Introduction, Mapping of S-plane to Z-plane, Impulse Invariance method,
Bilinear Z transformation (BLT) method, frequency warping, Prewarping, Design examples,
Practical filters e.g. Butterworth filters, Comparison of IIR and FIR Filters, Finite word length
effect

Filter Structures and DSP Processors

Basic Structures for FIR Systems: direct form, cascade form, structures for linear phase FIR
Systems, Examples
Filter structures for IIR Systems: direct form, cascade form, parallel form, examples.
DSP Processors Architecture Study: ADSP 21XX series: features, comparison with
conventional processor, Functional Block diagram: ALU, MAC, Barrel shifter, DAG, Registers
Introduction to Applications of DSP in speech and image processing
More aboutDigital Signal Processing Syllabus