The process of converting CT (continuous time) signal to discrete time signal is known as sampling. Sampling is very much necessary for digital systems because a computer cannot understand continuous time signals and sampling is the first step to convert any signal to its digital form.
Simplest form of sampling:-

Above figure shows the simplest process of obtaining samples through a high speed electronic switch. At the input side of switch a CT signal is applies and at the out put we obtain the sampled (discrete time) version of the signal applied at the input.
This is obtained by closing and opening the electronic switch at very high frequency known as sampling frequency.
Sampling frequency is the frequency at which switch is closed and opened is known as sampling frequency.
According to nyquist theorem the sampling frequency should be at least 2 times of fundamental frequency of the signal to be sampled.
Fs=2*Fm
where,
Fs= Sampling Frequency.
Fm= Fundamental frequency.
Sampling With Impulse Signal:-

Above shown is the impulse signal for discrete time.
If we create an impulse train from – infinite to + infinite and multiply the same to a CT signal then also we can convert a signal from CT to DT signal.
Figure below shows impulse train:-

Figure below shows Sampling with impulse train:-

In the figure above x(t) is input CT signal and p(t) is impulse train both of this signals are applied to multiplying box output xs(t)= x(t)*p(t).
The formula for impulse train is:-

By the property of impulse
| δ(t−t0)∗x(t)=x(t0)∗δ(t) |
Therefore for impulse train:

The code for the same is given below:-
close all;
clc;
clear all;
% Sampaling Frequency and defining time axes
fs=1000;
t=-1:1/fs:1-(1/fs);
f=1;
%General Variables
w=2*pi*f;
a=0;
% Impulse Signal
d=@(t) t==0;
% Sinc Function as CT Signal
syn=@(t) sinc(2*pi*f*t);
figure
plot(t,syn(t));
fss=100; %Sampling Freq (Number of Impulse that are desired in Impulse train)
T=1/fss; % Sampling Interval
%Creation of Impulse Train
for i=-1:T:1 % for Impulse Train
a=a+d(t-i);
end
%Plotting Impulse Train
figure;
plot(t,a);
title('impulse Train')
%Sampling of a signal with Impulse Train
a=a.*syn(t); % Multiplication of Impulse train with Sinc function
%Plotting of Sampled Signal
figure;
plot(t,a);
title('Impulse Train Multiplied with Sinc');
Below shown is figure of Sinc function:-
Sinc= Sin(wt)/wt;

Below shown is the figure of impulse train:-


Figure shown below is sampled sinc signal:-

Here our x(t) is sinc function
