Lecture 3

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 47

BIOSIGNAL PROCESSES AND ANALYSIS (2 2 3)

BME 366
(Lecture THREE)
Bio-Signals, ADC & DAC
Daniel Akwei Addo, PhD.
Casely Hayford Building (BME lab [office 1])
danieladdo@knust.edu.gh
Discrete-time signals and systems

➢ In this lecture, we will look at discrete-time signals and systems.

➢ As described earlier, a signal is a function of independent variables such as time, distance,


position, temperature, pressure, etc.

➢ Most signals are generated naturally but a signal can also be generated artificially using a
computer.

➢ And signals can be in any number of dimensions (1D, 2D, 3D, etc).

➢ We will be mainly studying time series signals, which are 1D signals with amplitude,
pressure, intensity, etc as a function of time.

➢ Later in the course, we will study static image signals which are 2D signals.
Discrete-time signals and systems

➢ Discrete-time systems operate on an input


signal, according to some prescribed
function and produce another output signal.

➢ For example, the input sequence could be a


noisy electrocardiogram (ECG) signal and the
system outputs a noise reduced ECG signal.

➢ In this example (see Figure), the discrete-


time system is a band-pass filter that
removes low frequency baseline noise and
high frequency powerline interference.
Discrete-time signals and systems
➢ There are some basic operations for discrete-time systems, which we will study in this lecture
but before we do that, we need to understand that discrete-time systems operate on
discrete-time signals and we need to obtain the latter from analogue signals.

Discrete-time signal
➢ In general, biological signals that are recorded are analogue and to process analogue signals
by digital means (like using a computer), we need to convert them to discrete-time form, i.e.
to convert them to a sequence of numbers defined at specific uniform intervals.

➢ This process is known as sampling.


Discrete-time signals and systems
Sampling

➢ Since most biological signals are 1D time series signals, we will focus our attention to such
signals where the independent variable is time.

➢ A discrete-time signal, x[n] is developed by uniformly sampling an analogue signal x(t) as


indicated in the Figure below.

➢ It is done by taking samples at specific uniform intervals of time (every value of x[n] is called
a sample) and the sampling interval is the time of one of these uniform intervals while the
sampling frequency is the number of uniform time intervals in one second normally
specified in Hz.
Discrete-time signals and systems
Aliasing

➢ Aliasing is a problem in the sampling process as it causes ambiguities in reconstruction, i.e.


distorts the sampled signal unrepresentative of the original signal.

➢ To avoid aliasing and be able to reconstruct the original signal without errors, the sampling
frequency has to be more than twice of the highest frequency contained in x(t).

➢ This is known as Nyquist theorem and the minimum frequency known as Nyquist frequency
(rate).
Discrete-time signals and systems
Discrete-time signals and systems
TASK ONE: MATLAB ILLUSTRATION OF SAMPLING AND ALIASING
Discrete-time signals and systems
Discrete-time signals and systems
➢ Recreate the analog signal using a sine wave with same the frequency and sampling
frequencies but with an amplitude of 10 mm
Discrete-time signals and systems
Discrete-time signals and systems
Sequences

➢ Sometimes, a discrete-time signal is known as a sequence and vice versa.

➢ A discrete-time signal may be a finite length or an infinite-length sequence.

➢ E.g.

➢ x[n]=1-2n4, -5≤n≤2 is a finite length sequence with length 2-(-5)+1=8

➢ but x[n]=sin(0.1n) is an infinite-length sequence.

TASK 2: Plot these two sequences using MATLAB


Discrete-time signals and systems
Discrete data plot using MATLAB
Discrete-time signals and systems
Zero Padding

TASK 3: Plot the above sequences using MATLAB


Discrete-time signals and systems
MATLAB representation of discrete signals
Discrete-time signals and systems
MATLAB representation of discrete signals
Discrete-time signals and systems
MATLAB representation of discrete signals
Discrete-time signals and systems
Basic Discrete-time System Operations

➢ There are several common operations that we will frequently encounter for discrete-time
systems and we will look at a few here.
Discrete-time signals and systems
Basic Discrete-time System Operations

➢ There are several common operations that we will frequently encounter for discrete-time
systems and we will look at a few here.
Discrete-time signals and systems
Basic Discrete-time System Operations

➢ There are several common operations that we will frequently encounter for discrete-time
systems and we will look at a few here.
Discrete-time signals and systems
Basic Discrete-time System Operations

➢ There are several common operations that we will frequently encounter for discrete-time
systems and we will look at a few here.
Discrete-time signals and systems
Basic Discrete-time System Operations

➢ There are several common operations that we will frequently encounter for discrete-time
systems and we will look at a few here.
Discrete-time signals and systems
Basic Discrete-time System Operations

➢ There are several common operations that we will frequently encounter for discrete-time
systems and we will look at a few here.
Discrete-time signals and systems
Basic Discrete-time System Operations
Discrete-time signals and systems
Basic Discrete-time System Operations
Discrete-time signals and systems
Basic Discrete-time System Operations
Discrete-time signals and systems
Basic Discrete-time System Operations
Discrete-time signals and systems
Basic Discrete-time System Operations
Discrete-time signals and systems
Basic Discrete-time System Operations
Discrete-time signals and systems
Basic Discrete-time System Operations
Discrete-time signals and systems
Basic Discrete-time System Operations
Discrete-time signals and systems
Basic Discrete-time System Operations
Discrete-time signals and systems
Signal Generation and noise contamination using MATLAB SIMULINK
➢ Open the Signal model by typing

ex_gstut3

➢ At the MATLAB® command prompt. This model contains a Scope block that displays the
original sine wave and the sine wave with white noise added
Discrete-time signals and systems
Signal Generation and contamination using MATLAB SIMULINK

➢ Run the setup

➢ Obtain plots for both the uncontaminated


and contaminated signal at frequency of
0.5 Hz, 1 Hz, 2 Hz and 4Hz.

➢ Explain the effect of increasing frequency


on the uncontaminated signal.
Quantization with MATLAB
➢ Scalar quantization is a process that maps all inputs within a specified range to a common
value.

➢ This process maps inputs in a different range of values to a different common value.

➢ In effect, scalar quantization digitizes an analog signal.

➢ Two parameters determine a quantization: a partition and a codebook.

➢ A quantization partition defines several contiguous, nonoverlapping ranges of values within


the set of real numbers.

➢ To specify a partition in the MATLAB® environment, list the distinct endpoints of the
different ranges in a vector.
Quantization with MATLAB
➢ A codebook tells the quantizer which common value to assign to inputs that fall into each
range of the partition.

➢ Represent a codebook as a vector whose length is the same as the number of partition
intervals.

➢ For example, the vector

codebook = [-1, 0.5, 2, 3];

is one possible codebook for the partition [0,1,3].


Quantization with MATLAB
Section Overview

➢ Quantization distorts a signal.

➢ You can reduce distortion by choosing appropriate partition and


codebook parameters.

➢ However, testing and selecting parameters for large signal sets


with a fine quantization scheme can be tedious.

➢ One way to produce partition and codebook parameters easily is


to optimize them according to a set of so-called training data
(Machine Learning Models).
Quantization with MATLAB
Scalar Quantization Example 1

➢ The code below shows how the quantiz function uses partition and codebook to map a real
vector, samp, to a new vector, quantized, whose entries are either -1, 0.5, 2, or 3.

➢ samp = [-2.4, -1, -.2, 0, .2, 1, 1.2, 1.9, 2, 2.9, 3, 3.5, 5];

➢ partition = [0,1,3];

➢ codebook = [-1, 0.5, 2, 3];

➢ [index,quantized] = quantiz(samp,partition,codebook);

➢ quantized
Quantization with MATLAB
Scalar Quantization Example 1
The output is below.

quantized =

Columns 1 through 6

-1.0000 -1.0000 -1.0000 -1.0000 0.5000 0.5000

Columns 7 through 12

2.0000 2.0000 2.0000 2.0000 2.0000 3.0000

Column 13

3.0000
Quantization with MATLAB
Scalar Quantization Example 2

➢ This example illustrates the nature of scalar quantization more clearly.

➢ After quantizing a sampled sine wave, it plots the original and quantized signals.

➢ The plot contrasts the x's that make up the sine curve with the dots that make up the
quantized signal.

➢ The vertical coordinate of each dot is a value in the vector codebook.


Quantization with MATLAB
Scalar Quantization Example 2

➢ t = [0:.1:2*pi]; % Times at which to sample the sine function

➢ sig = sin(t); % Original signal, a sine wave

➢ partition = [-1:.2:1]; % Length 11, to represent 12 intervals

➢ codebook = [-1.2:.2:1]; % Length 12, one entry for each interval

➢ [index,quants] = quantiz(sig,partition,codebook); % Quantize.

➢ plot(t,sig,'x',t,quants,'.’)

➢ legend('Original signal','Quantized signal’);

➢ axis([-.2 7 -1.2 1.2])


Quantization with MATLAB
Scalar Quantization Example 2
Quantization with MATLAB
Example: Optimizing Quantization Parameters

➢ The lloyds function optimizes the partition and codebook according to the Lloyd
algorithm.

➢ The code below optimizes the partition and codebook for one period of a sinusoidal
signal, starting from a rough initial guess.

➢ Then it uses these parameters to quantize the original signal using the initial guess
parameters as well as the optimized parameters.

➢ The output shows that the mean square distortion after quantizing is much less for the
optimized parameters.

➢ The quantiz function automatically computes the mean square distortion and returns it
as the third output parameter.
Quantization with MATLAB
% Start with the setup from 2nd example in "Quantizing a Signal."
t = [0:.1:2*pi];
sig = sin(t);
partition = [-1:.2:1];
codebook = [-1.2:.2:1];
% Now optimize, using codebook as an initial guess.
[partition2,codebook2] = lloyds(sig,codebook);
[index,quants,distor] = quantiz(sig,partition,codebook);
[index2,quant2,distor2] = quantiz(sig,partition2,codebook2);
% Compare mean square distortions from initial and optimized
[distor, distor2] % parameters.

The output is TRY


ans = ➢ Plot the analog signal, optimized quantized signal and
0.0148 0.0024 the unoptimized quantized signal on the same graph.
Quantization with MATLAB
➢ In the previous examples, the values of partition and codebook were written out.

➢ Better to create the partition and codebook using characteristics of the signal.

➢ Try this:
Ts=0.0001;
t=0:.00001:20*Ts;
sig=sin(2000*pi*t)+cos(2000*pi*t);
maxsig=max(sig); %signal max
interv=2*maxsig/(2^3-1); %interval length for 8 levels resolution
u=maxsig+interv;
partition = [-maxsig:interv:maxsig];
codebook = [-maxsig:interv:u];
[index,quants] = quantiz(sig,partition,codebook); % Quantize.
plot(t,sig,'-',t,quants,'-');
legend('Original signal','Quantized signal');
Quantization with MATLAB
Ts=0.0001;
t=0:.00001:20*Ts;
sig=sin(2000*pi*t)+cos(2000*pi*t);
maxsig=max(sig); %signal max
interv=2*maxsig/(2^3-1); %interval length for 8 levels resolution
u=maxsig+interv;
partition = [-maxsig:interv:maxsig];
codebook = [-maxsig:interv:u];
[index,quants] = quantiz(sig,partition,codebook); % Quantize.
plot(t,sig,'-',t,quants,'-');
legend('Original signal','Quantized signal');

➢ Determine the distortion (quantization error or noise) in the above.

➢ Increase the resolution to 16, 32, 64 and 128 levels and determine the distortion for each
resolution.

➢ For the 8 levels resolution, apply Lloyds optimization algorithm and assess the effect on the
quantization noise.

You might also like