% EXPERIMENT 1
% ANALOG SIGNAL SAMPLING AND RECONSTRUCTION
clc;
clear all;
close all;
fm = 1000; % Message frequency
fs = 8000; % Sampling frequency
Fs = 200000; % Sampling rate
t = 0:1/Fs:0.01;
Ts = 1/fs;
% Analog input signal (5 Vpp)
m = 2.5*sin(2*pi*fm*t);
% Sampling clock (50% duty cycle)
clock = double(mod(t,Ts) < Ts/2);
% Natural sampling
natural = m .* clock;
% Sample and Hold
N = round(Ts*Fs);
sample_index = floor(t/Ts)*N + 1;
sample_index(sample_index > length(t)) = length(t);
hold_signal = m(sample_index);
% Flat Top Sampling
flat_top = hold_signal .* clock;
% FFT based Low Pass Filter
L = length(t);
Y = fftshift(fft(flat_top));
f = ((0:L-1)-floor(L/2))*(Fs/L);
cutoff = 2000;
Y(abs(f)>cutoff) = 0;
reconstructed = real(ifft(ifftshift(Y)));
% Plotting
figure(1);
subplot(4,1,1);
plot(t,m,'b','LineWidth',1.5);
title('Analog Input Signal');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;
subplot(4,1,2);
plot(t,natural,'r');
title('Natural Sampling');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;
subplot(4,1,3);
plot(t,hold_signal,'g');
title('Sample and Hold');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;
subplot(4,1,4);
plot(t,reconstructed,'m','LineWidth',1.5);
title('Reconstructed Output');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;
disp('Experiment 1 Completed Successfully');
To embed this project on your website, copy the following code and paste it into your website's HTML: