You are on page 1of 6

BME-303 Bio-Signal Processing

EXPERIMENT 02

OBJECTIVE

To perform sampling on a continuous time signal using MATLAB.

EQUIPMENTS

 Personal Computer (PC)


 MATLAB Software.

THEORY

Signals are physical quantities that carry information in their patterns of variation.
Continuous time signals are continuous functions of time, while discrete-time signals are
sequences of numbers. If the values of a sequence are chosen from a finite set of numbers, the
sequence is known as a digital signal. Continuous-time, continuous-amplitude signals are also
known as analog signals.

Signal processing is concerned with the acquisition, representation, manipulation,


transformation, and extraction of information from signals. In analog signal processing these
operations are implemented using analog electronic circuits. Digital signal processing
involves the conversion of analog signals into digital, processing the obtained sequence of
finite precision numbers using a digital signal processor or general-purpose computer, and, if
necessary, converting the resulting sequence back into analog form. When stored in a digital
computer, the numbers are held in memory locations, so they would be indexed by memory
address. In order to bridge the gap between analog and digital domain, we have to perform
two basic operations Sampling and Quantization.

Sampling

It is the process of acquiring data at discrete (finite) instants of time.

Sampling Theorem

A continuous time signal x(t) can be reconstructed exactly from its samples x(n)=x(nTs), if
the samples are taken at a rate Fs=1/Ts that is greater than 2*Fmax.

Nyquist rate

When sampling frequency is equal to the twice the input signal frequency, the sampling rate
is called Nyquist rate.

Aliasing

A common problem that arises when sampling a continuous signal is aliasing, where a
sampled signal has replications of its sinusoidal components which can interfere with other

Department of Biomedical Engineering, SHU.


BME-303 Bio-Signal Processing

components. Itis an effect that causes two discrete time signals to become indistinct due to
improper sampling (fd>1/2). Aliasing also occurs on television whenever we see a car whose
tires appear to be spinning in the wrong direction. A television broadcast can be thought of as
a series of images, sampled at a regular rate, appearing on screen. If the wheels happen to
rotate less than a full circle between frames (images), then they appear to be turning slowly in
the opposite direction.

LAB TASK’s
Q1: Perform sampling on a given signal using MATLAB.
(a)
x(t) = A*sin(2*pi*F*t)
Here,
Amplitude (A) = 1m
Frequency(F)=2 Hz.

Code:
%Plotting the Original Signal:
t=(0:0.001:1);
A=1;%amplitude
F=2;%frequency
x=A*sin(2*pi*F*t);%signal
subplot(2,1,1)
plot(t,x)
title('Original Continous signal')
%Performing the Sampling on Signal
FS=10*F;%sampling frequency
TS=1/FS;%sampling time
N=FS;
N_1=0:TS:N*TS;
X=A*sin(2*pi*F*N_1);%sampled signal
subplot(2,1,2);
stem(N_1,X)
title('Sampled signal')

Output:
Original Continous signal
1

0.5

-0.5

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Sampled signal
1

0.5

-0.5

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Fig no. 01: Sampled signal output

Department of Biomedical Engineering, SHU.


BME-303 Bio-Signal Processing

Interpretation:
This code produces a continuous sine wave sound with a 2 Hz frequency, which is then
sampled to provide a discrete representation. The smooth sine wave, which symbolizes
the initial continuous signal, is shown in the top subplot. The sampled signal, where
the signal's values are determined at certain time points, is displayed in the bottom
subplot. Sampling is crucial in the signal processing process because it allows
continuous signals to be transformed into digital data that can be processed by
computers or other digital devices. It is a key idea in a variety of industries, including
audio processing, communications, and more.

(b)
x(t) = sin(2*pi* F1*t)+ sin(2*pi* F2*t)
Here,
Frequency(F1)=10 Hz.
Frequency(F2)=20 Hz.

Note: Attached the results including code and interpret it.


Code:
%Plotting the Original Signal:
t=(0:0.001:1);
A=1;%amplitude
F1 = 10; %frequency1
F2 = 20; %frequency2
x = A * (sin(2*pi*F1*t) + sin(2*pi*F2*t));%signal
subplot(2,1,1)
plot(t,x)
title('Original Continous signal')
%Performing the Sampling on Signal
FS=100;%sampling frequency
TS=1/FS;%sampling time
N=FS;
N_1=0:TS:N*TS;%vector for sample signal
X = A * (sin(2*pi*F1*N_1) + sin(2*pi*F2*N_1));
subplot(2,1,2);
stem(N_1,X)
title('Sampled signal')

Output:
Original Continous signal
2

-1

-2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Sampled signal
2

-1

-2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Fig no. 02: Sampled Signal output

Department of Biomedical Engineering, SHU.


BME-303 Bio-Signal Processing

Interpretation:

This code demonstrates how a continuous signal with two distinct frequency components,10
Hz and 20 Hz, can be sampled in order to create a discrete representation. The bottom subplot
illustrates the discrete sampling of this signal at regular intervals, highlighting the
significance of sampling in signal processing and digital representation. The top subplot
displays the complex continuous signal created by adding two sinusoidal waves.

Q2: By following the Nyquist criteria reconstruct the signal that you have generated in Q1
(a).

Note: Attached the results including code and interpret it.

Code:

%Plotting the Original Signal:


t=(0:0.001:1);
A=1;%amplitude
F=2;%frequency
x=A*sin(2*pi*F*t);%signal
subplot(3,1,1)
plot(t,x)
title('Original Continous signal')
%Performing the Sampling on Signal
FS=10*F;%sampling frequency
TS=1/FS;%sampling time
N=FS;
N_1=0:TS:N*TS;
X=A*sin(2*pi*F*N_1);%sampled signal
subplot(3,1,2);
stem(N_1,X)
title('Sampled signal')
%Reconstructing the Original signal
T1 = linspace(0, max(N_1), max(N_1)/0.01);%time vector
XS = interp1(N_1, X, T1, 'spline');%recontructed signal
subplot(3,1,3)
plot(T1,XS)
title('Reconstructed signal')

Department of Biomedical Engineering, SHU.


BME-303 Bio-Signal Processing

Output:

Original Continous signal


1

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Sampled signal
1

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Reconstructed signal
1

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Fig no. 03: Reconstructed Signal

Interpretation:

The code illustrates the steps involved in sampling a continuous signal, reconstructing it
from the discrete samples, and illustrating the effect of sampling on the signal.

Q3: Can you reconstruct the signal that you have generated in Q1 (a) if don’t follow Nyquist
criteria?
Note: Justify your statement.

Code:
%Plotting the Original Signal:
t=(0:0.001:1);
A=1;%amplitude
F=2;%frequency
x=A*sin(2*pi*F*t);%signal
subplot(3,1,1)
plot(t,x)
title('Original Continous signal')
%Performing the Sampling on Signal
FS=3*F;%sampling frequency
TS=1/FS;%sampling time
N=FS;
N_1=0:TS:N*TS;
X=A*sin(2*pi*F*N_1);%sampled signal
subplot(3,1,2);
stem(N_1,X)
title('Sampled signal')
%Reconstructing the Original signal
T1 = linspace(0, max(N_1), max(N_1)/0.01);%time vector
XS = interp1(N_1, X, T1, 'spline');%recontructed signal
subplot(3,1,3)
plot(T1,XS)
title('Reconstructed signal')

Department of Biomedical Engineering, SHU.


BME-303 Bio-Signal Processing

Output:

Original Continous signal


1

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Sampled signal
1

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Reconstructed signal
1

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Fig no. 04: Reconstructed signal if it’s don’t follow Nyquist criteria

Statement:

The Nyquist theorem states that in order to accomplish correct reconstruction, the
sampling frequency must be at least twice that of the original signal. The code offered
does not follow this rule. The sampling frequency in this code is set to 10 times the
original frequency rather than being set at twice the original frequency. As a result,
there are aliasing problems, making it impossible to accurately recreate the original
signal.
Q4: Why interpolation is used in reconstruction of sampled signal?

Interpolation is used in the reconstruction of sampled signals to approximate the original


continuous-time signal from its discrete samples. This is necessary because the sampling
process reduces the information content of the signal, and therefore some of the original
signal is lost.

CONCLUSION:

In this lab, we explored how to sample a continuous-time signal using MATLAB. Sampling,
a fundamental idea in signal processing, is essential for transforming continuous signals into
discrete representations appropriate for digital processing.

Department of Biomedical Engineering, SHU.

You might also like