/* Implementation of General Difference Equation based array mapping
C program to implement the difference equation of the LSI system
which is given as
y(n)=-[a1*y(n-1)+a2*y(n-2)+a3*y(n-3)+......]
+b0*x(n)+b1*x(n-1)+b2*x(n-2)+....
INPUTS: 1.Number of coefficients ak,denoted as N.
2.Values of a1,a2,a3,...etc
3.Number of coefficients bk,denoted as M.
4.Values of b0,b1,b2,...etc
5.Number of samples of x(n),denoted as L.
6.Values of x(0),x(1),x(2),...etc
OUTPUTS: The computed output sequence y(n) is according to the specified
format of difference euation as above.
ASSUMPTIONS: 1.The number of samples computed for y(n) are same as number
of input samples.
2.All initial conditions are assumed zero.
NOTE: Actually there is no specific formula for number of samples in y(n) depend
upon type of input x(n), coefficients ak and bk and initial conditions.
*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int N,M,k,L,n;
float a[10],b[10],x[100],y[100],sum_x,sum_y;
clrscr();
printf("\n\t Implementation of General Difference Eqn based array mapping");
printf("\n\n Enter the number of coefficients a[k]=");
scanf("%d",&N);
printf("\n\n Enter the values coefficients a[k]:\n");
for(k=1;k<=N;k++)
{
printf("a%d=",k);
scanf("%f",&a[k]);
}
printf("\n\n Enter the number of coefficients b[k]=");
scanf("%d",&M);
printf("\n\n Enter the values coefficients b[k]:\n");
for(k=0;k<M;k++)
{ // values of b0,b1,b2,....
printf("b%d=",k);
scanf("%f",&b[k]);
}
printf("\n\n Enter the number of samples of x(n):");
scanf("%d",&L);
for(k=0;k<L;k++)
{ // values of x(0),x(1),x(2),....
printf("x(%d)=",k);
scanf("%f",&x[k]);
}
printf("\n The computed values of y(n) are:");
for(n=0;n<L;n++)
{
sum_y=0;
sum_x=0;
for(k=1;(k<=n)&&(k<=N);k++) //computation of a1*y(n-1)+a2*y(n-2)+a3*y(n-3)+..
{
sum_y+=a[k]*y[n-k];
}
for(k=0;(k<=n)&&(k<=n)&&(k<M);k++)
{ //computation of b0*x(n)+b1*x(n-1)+b2*x(n-2)+..
sum_x+=b[k]*x[n-k];
}
y[n]=-sum_y+sum_x;
printf("\n y(%d)=%f",n,y[n]);
}
getch();
}
*op****************
Implementation of General Difference Eqn based array mapping
Enter the number of coefficients a[k]=3
Enter the values coefficients a[k]:
a1=1
a2=2
a3=3
Enter the number of coefficients b[k]=3
Enter the values coefficients b[k]:
b0=3
b1=2
b2=1
Enter the number of samples of x(n):2
x(0)=1
x(1)=2
The computed values of y(n) are:
y(0)=3.000000
y(1)=5.000000
C program to implement the difference equation of the LSI system
which is given as
y(n)=-[a1*y(n-1)+a2*y(n-2)+a3*y(n-3)+......]
+b0*x(n)+b1*x(n-1)+b2*x(n-2)+....
INPUTS: 1.Number of coefficients ak,denoted as N.
2.Values of a1,a2,a3,...etc
3.Number of coefficients bk,denoted as M.
4.Values of b0,b1,b2,...etc
5.Number of samples of x(n),denoted as L.
6.Values of x(0),x(1),x(2),...etc
OUTPUTS: The computed output sequence y(n) is according to the specified
format of difference euation as above.
ASSUMPTIONS: 1.The number of samples computed for y(n) are same as number
of input samples.
2.All initial conditions are assumed zero.
NOTE: Actually there is no specific formula for number of samples in y(n) depend
upon type of input x(n), coefficients ak and bk and initial conditions.
*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int N,M,k,L,n;
float a[10],b[10],x[100],y[100],sum_x,sum_y;
clrscr();
printf("\n\t Implementation of General Difference Eqn based array mapping");
printf("\n\n Enter the number of coefficients a[k]=");
scanf("%d",&N);
printf("\n\n Enter the values coefficients a[k]:\n");
for(k=1;k<=N;k++)
{
printf("a%d=",k);
scanf("%f",&a[k]);
}
printf("\n\n Enter the number of coefficients b[k]=");
scanf("%d",&M);
printf("\n\n Enter the values coefficients b[k]:\n");
for(k=0;k<M;k++)
{ // values of b0,b1,b2,....
printf("b%d=",k);
scanf("%f",&b[k]);
}
printf("\n\n Enter the number of samples of x(n):");
scanf("%d",&L);
for(k=0;k<L;k++)
{ // values of x(0),x(1),x(2),....
printf("x(%d)=",k);
scanf("%f",&x[k]);
}
printf("\n The computed values of y(n) are:");
for(n=0;n<L;n++)
{
sum_y=0;
sum_x=0;
for(k=1;(k<=n)&&(k<=N);k++) //computation of a1*y(n-1)+a2*y(n-2)+a3*y(n-3)+..
{
sum_y+=a[k]*y[n-k];
}
for(k=0;(k<=n)&&(k<=n)&&(k<M);k++)
{ //computation of b0*x(n)+b1*x(n-1)+b2*x(n-2)+..
sum_x+=b[k]*x[n-k];
}
y[n]=-sum_y+sum_x;
printf("\n y(%d)=%f",n,y[n]);
}
getch();
}
*op****************
Implementation of General Difference Eqn based array mapping
Enter the number of coefficients a[k]=3
Enter the values coefficients a[k]:
a1=1
a2=2
a3=3
Enter the number of coefficients b[k]=3
Enter the values coefficients b[k]:
b0=3
b1=2
b2=1
Enter the number of samples of x(n):2
x(0)=1
x(1)=2
The computed values of y(n) are:
y(0)=3.000000
y(1)=5.000000
its working it helped me thank you soo much
ReplyDeleteits working it helped me thank you soo much
ReplyDelete