Experiment No:1 Sampling and Reconstruction
Experiment No:1 Sampling and Reconstruction
Experiment no:1
Sampling and Reconstruction
Aim: To study sampling and reconstruction of signal
Objective: Develop a program to sample a continuous time signal and convert it to Discrete
Time Signal.
Problem Definition:
1. Sample the input signal and display first 50 samples. Calculate data rate and bit rate.
2. Reconstruct the original signal and display the original and reconstructed signals.
3. Vary the sampling frequency and observe the change in the quality of reconstructed
signal
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
double y,f;
int t,fs,fc,fsi;
char ch[10];
fc=3;
clrscr();
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
outtextxy(2,5,"CONTINUOUS SIGNAL : x(t)=50sin(2*pi*3*t)");
line(0,100,800,100);
for(t=0;!(kbhit());t++)
{
y=50*sin(2*(3.14/180)*fc*t);
putpixel(t,-y+100,15);
delay(1);
}
getche();
printf("\nEnter the sampling frequency");
scanf("%d",&fs);
line(0,215,800,215);
fsi=fs;
f=3.0/fs;
outtextxy(2,155,"DISCRETE SIGNAL : x(n)=50sin(2*pi*");
sprintf(ch,"(3/%d)",fsi);
outtextxy(275,155,ch);
outtextxy(325,155,"*n");
for(t=0;!(kbhit());t++)
Page no.
{
y=50*sin(2*(3.14/180)*f*t);
putpixel(t,-y+215,15);
delay(1);
}
getche();
outtextxy(2,270,"RECONSTRUCTED SIGNAL");
line(0,350,800,350);
if(fs<2*fc)
{
for(t=0;!(kbhit());t++)
{
y=50*sin(2*3.14/180-2*(3.14/180)*f*fs*t);
putpixel(t,-y+350,15);
delay(1);
}
getche();
outtextxy(2,405,"Original signal is not obtained since Niquiste criteria");
outtextxy(2,415,"is not followed");
}
else
{
for(t=0;!(kbhit());t++)
{
y=50*sin(2*(3.14/180)*f*fs*t);
putpixel(t,-y+350,15);
delay(1);
}
getche();
outtextxy(2,405,"Original signal is obtained since Niquiste criteria");
outtextxy(2,415,"is followed");
}
getch();
closegraph();
}
Page no.
Output:
Page no.