Name: Aryan
Roll No: 23BEC022
AIM:
To study the operation of sampling and reconstruction.
THEORY:
A continuous signal can be represented in the digital version in the form of samples. In
sampling, the input signal is an analog signal and the second input signal is a sampling
signal, which is a pulse train signal and each pulse is equidistant with a period of Ts.
The sampling signal frequency should be more than twice of the input analog signal
frequency i.e. Fs ≥ 2Fm. If this condition satisfies, the analog signal is perfectly represented
in discrete form.
When sampling frequency equals twice the input signal frequency i.e. Fs = 2Fm, it is known
as the Nyquist rate.
If the sampling frequency (Fs) is less than twice the input signal frequency i.e. Fs < 2Fm, an
effect called Aliasing occurs. Here, analog signals may lose their values for certain time
intervals and appear distorted.
Signals that are sampled following Nyquist Rule are well suited for reconstruction to
recover the original signal.
PROCEDURE:
1. Open MATLAB on your computer.
2. Create a continuous signal and plot it with a certain frequency.
3. Sample this continuous signal with proper sampling frequency satisfying Nyquist
criterion.
4. Plot this sampled signal using stem function.
Name: Aryan
Roll No: 23BEC022
Name Aryan , Roll No 23BEC022
MATLAB CODE:
1 To generate a sine wave and sample the sine wave .
clc
clear;
close all;
f = 5;
t = -1:0.001:1;
a = sin(2*pi*f*t);
subplot(2,1,1)
plot(t, a, 'LineWidth', 1.5);
xlabel("Time")
ylabel("Amplitude")
title("Sine Wave")
Ts = 0.005;
n = -1:Ts:1;
ys = sin(2*pi*f*n);
subplot(2,1,2)
stem(n,ys);
xlabel("Time")
ylabel("Amplitude")
title("Sampled Sine Wave")
2 To generate and Unit Step Signal and then Sample it .
clc;
clear;
close all;
Ts = 5;
t = -100:1:100;
Name: Aryan
Roll No: 23BEC022
for k = 1:length(t)
if t(k) >= 0
y(k) = 1;
else
y(k) = 0;
end
end
subplot(2,1,1)
plot(t, y);
xlabel('Continuous Time Axis');
ylabel('Amplitude');
title('Continuous-Time Unit Step');
n = -20:Ts:20;
ys = (n >= 0);
subplot(2,1,2)
stem(n, ys, 'filled');
xlabel('Discrete Time Axis');
ylabel('Amplitude');
title('Discrete-Time Unit Step');
grid on;
T3 To generate a exponential signal and then sample it .
clc
clear;
close all;
f = 5;
t = -1:0.001:1;
a = exp(-t);
subplot(2,1,1)
plot(t, a, 'LineWidth', 1.5);
xlabel("Time")
ylabel("Amplitude")
title("Exponential Function")
Ts = 0.005;
n = -1:Ts:1;
ys = exp(-n);
subplot(2,1,2)
Name: Aryan
Roll No: 23BEC022
stem(n,ys);
xlabel("Time")
ylabel("Amplitude")
title("Sampled Exponential Function ")
4 To generate a Ramp Function and sample it.
clc;
clear;
close all;
Ts = 5;
t = -100:1:100;
for k = 1:length(t)
if t(k) >= 0
y(k) = t(k);
else
y(k) = 0;
end
end
subplot(2,1,1)
plot(t, y);
xlabel('Continuous Time Axis');
ylabel('Amplitude');
title('Continuous-Time Ramp Signal');
n = -100:Ts:100;
for k = 1:length(n)
if n(k) >= 0
ys(k) = n(k);
else
ys(k) = 0;
end
end
subplot(2,1,2)
stem(n, ys, 'filled');
xlabel('Discrete Time Axis');
Name: Aryan
Roll No: 23BEC022
ylabel('Amplitude');
title('Discrete-Time Ramp Signal');
grid on;
5 To generate a cosine wave and sample it.
clc
clear;
close all;
f = 5;
t = -1:0.001:1;
a = cos(2*pi*f*t);
subplot(2,1,1)
plot(t, a, 'LineWidth', 1.5);
xlabel("Time")
ylabel("Amplitude")
title("Cosine Function")
Ts = 0.005;
n = -1:Ts:1;
ys = cos(2*pi*f*n);
subplot(2,1,2)
stem(n,ys);
xlabel("Time")
ylabel("Amplitude")
title("Sampled Cosine Function ")
6 To plot a Unit Impulse Function
clc;
clear;
close all;
x = -10:10;
for i = 1:21
if x(i)==0
y(i)=1;
else
y(i)=0;
Name: Aryan
Roll No: 23BEC022
end
end
subplot(2,1,1)
stem(x,y)
xlabel("Time Axis")
ylabel("Amplitude")
title("Unit Impulse Function")