Saturday, August 21, 2010

TO GENERATE AN AMPLITUDE MODULATED WAVE

0 comments
SOURCE CODE:
/*To generate an amplitude modulated wave*/
#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int gm,gd=DETECTED;
float Ec,Wc=300,Ws=15,m,t,grx,gry,y;
printf("Amplitude of carrier wave: \n");
scanf("%f",&Ec);
printf("Modulation factor: \n");
scanf("%f",&m);
initgraph(&gd,&gm,"");
setcolor(WHITE);
line(10,10,10,200);
line(10,100,300,100);
for(t=0;t<9;t=t+.0001)
{
grx=10+325*t;
y=Ec*cos(Wc*t);
gry=100-y*10;
putpixel(grx,gry,RED);
}
line(10,200,10,500);
line(10,350,300,350);
for(t=0;t<9;t=t+.0001)
{
grx=10+325*t;
y=m*Ec*cos(Ws*t);
gry=350-y*10;
putpixel(grx,gry,BLUE);
}
line(350,90,950,400);
line(350,248,630,248);
for(t=0;t<87;t=t+.0001)
{
grx=350+325*t;
y=Ec*(1+m*cos(Ws*t))*cos(Wc*t);
gry=250-y*10;
putpixel(grx,gry,YELLOW);
}
getch();
closegraph();
}




Algorithm:

1.Start
2.Read Ec
3.Assign Wc=300,Ws=15.
4.Read m,Ec,Wc,Ws
5.For t varying from 0 to 8999
Do the following
a).Compute grx=10+325*t
b).Compute y=Ec*cos(Wc*t)
c).Compute gry=100-y*t
d).Draw the coordinates
6. For t varying from 0 to 8999
Do the following
a).Compute grx=10+325*t
b).Compute y=m*Ec*cos(Ws*t)
c).Compute gry=350-y*t
d).Draw the coordinates
7.For t varying from 6 to 8699
Do the following
a).Compute grx=350+325*t
b).Compute y=Ec*(1+m*cos(cosWs*t)*cos(Wc)+t)
c).Compute gry=350-y*t
d).Draw the coordinates
8.Stop



Leave a Reply