Implementation of General Diffrence Equation

Posted by fasxxzczc on Wednesday 21 March 2012

  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:  }  

{ 0 comments... read them below or add one }

Post a Comment