Prog :- Find Output of a given System for given input sequence using Linear Convolution.
/**************************************************************************/
#include<iostream.h>#include<conio.h>
#include<math.h>
/**************************************************************************/
class list
{
public:
int index,value,length;
list *next;
list()
{
value=0;
}
list *accepthn(list *w);
list *acceptxn(list *w);
list *convol(list *w,list *v);
};
list *p,*q,*yy,*qq,*r,*head,*head1,*head2;
list *f,*h,*x,*head3;
int i,j,k,l,m,e,xe,he;
int y[201]={0};
int xlen,hlen,max,size,xlo,xup,hlo,hup;
/**************************************************************************/
list *list::accepthn(list *w){
i=0;
head=q=w;
do
{
p=new list;
cout<<"\n Enter index & Element ==> ";
cin>>p->index>>p->value;
p->next=NULL;
if(head==NULL)
{
head=p;
q=head;
}
else
{
q->next=p;
q=p;
}
cout<<"\n Continue ? [1/0]==> ";
cin>>e;
i++;
q->length++;
}while(e==1);
return(head);
}
/**************************************************************************/
list *list::convol(list *x,list *h){
cout<<"\n \n Impulse Response Of Given System is ==> \n{ ";
for(i=(xlo+hlo);i<=(xup+hup);i++)
y[i]=0;
for(i=(xlo+hlo);i<=(xup+hup);i++)
{
y[i]=0;
head1=x;
head2=h;
for(head2=h;head2!=NULL;head2=head2->next)
{
for(head1=x;head1!=NULL;head1=head1->next)
{
if(head1->index==i-head2->index)
y[i]=y[i]+(head1->value*head2->value);
}
}
cout<<y[i]<<" ";
}
cout<<" }";
}
/**************************************************************************/
void main(){
clrscr();
B: xlo=hlo=100; //Accepting System Input h(n)
xup=hup=-100;
cout<<"\n System h(n) ==> ";
h=r->accepthn(NULL);
cout<<"\n h(n) ==> { ";
head1=h;
do
{
if(head1->index==0)
cout<<" @";
cout<<" -> "<<head1->value;
if(head1->index>hup)
hup=head1->index;
if(head1->index<hlo)
hlo=head1->index;
head1=head1->next;
}while(head1!=NULL);
cout<<" }";
A: xlo=100; //Accepting Input x(n)
xup=-100;
cout<<"\n Input x(n) ==> ";
x=r->accepthn(NULL);
cout<<"\n h(n) ==> { ";
head1=x;
do
{
if(head1->index==0)
cout<<" @";
cout<<" -> "<<head1->value;
if(xup<head1->index)
xup=head1->index;
if(xlo>head1->index)
xlo=head1->index;
head1=head1->next;
}while(head1!=NULL);
yy=r->convol(x,h);
cout<<"\n Do You Want to change input x(n) [1/0] => ";
cin>>xe;
if(xe==1)
goto A;
cout<<"\n Do You Want to change System Imput h(n) [1/0] => ";
cin>>he;
if(he==1)
goto B;
getch();
}
/********************************** Output **********************************/
System h(n) ==> Enter index & Element ==> 0 1
Continue ? [1/0]==> 1
Enter index & Element ==> -1 1
Continue ? [1/0]==> 1
Enter index & Element ==> 1 1
Continue ? [1/0]==> 0
h(n) ==> { @ -> 1 -> 1 -> 1 }
Input x(n) ==>
Enter index & Element ==> -99 2
Continue ? [1/0]==> 1
Enter index & Element ==> 99 3
Continue ? [1/0]==> 0
h(n) ==> { -> 2 -> 3
Impulse Response Of Given System is ==>
{ 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 }
Do You Want to change input x(n) [1/0] => 0
Do You Want to change System Imput h(n) [1/0] => 0
*/
No comments:
Post a Comment