0% found this document useful (0 votes)
260 views

Bio-Signal Processing Lab. Lec 1

This document provides instructions for two MATLAB experiments on signal processing. The first experiment introduces MATLAB and teaches how to plot different signal types, including continuous and discrete signals. It also covers shifting, folding, and scaling signals. The second experiment covers signal processing techniques like convolution in MATLAB. It includes examples of shifting, folding, and convolving discrete signals. Students are assigned homework problems applying these techniques and are expected to submit lab reports documenting their work.

Uploaded by

Abdi Teferi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
260 views

Bio-Signal Processing Lab. Lec 1

This document provides instructions for two MATLAB experiments on signal processing. The first experiment introduces MATLAB and teaches how to plot different signal types, including continuous and discrete signals. It also covers shifting, folding, and scaling signals. The second experiment covers signal processing techniques like convolution in MATLAB. It includes examples of shifting, folding, and convolving discrete signals. Students are assigned homework problems applying these techniques and are expected to submit lab reports documenting their work.

Uploaded by

Abdi Teferi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

Jimma University Institute of Technology

School of Biomedical Engineering


Bio-signal Processing Lab.
Experiment 1

Introduction to MATLAB and signal


processing
Eden T. and Derartu D.
Experiment Objective
• To be familiar with MATLAB environment.
• To have hands on practice on MATLAB.
• To understand how to draw different type of
signal in MATLAB.
• To understand how to implement the different
signal types on MATLAB.
What is MATLAB?
• An interactive software system for numerical
computations and graphics .
• Designed for matrix computations:
– Solving system of linear equations,

– Computing eigenvalues and eigenvectors,

– Factoring matrices , etc.


MATLAB Application areas
• It is used in a range of applications
including:
– Signal processing
– Communications
– Image and video Processing
– Control systems
– Test and measurement
– Artificial intelligence
Working with MATLAB

https://matlab.mathworks.com/
Working with MATLAB
• To see list of variables on your workspace
– >> who % list variables
– >> whos % list all information
• Editor window(M-file): used to run and edit
commands /programs redundantly.
• MATLAB has built in functions which can be
used in Various computations.
– >>log(100), exp(a^2)
What is SIGNAL?
• Signal is a numerical quantity that can vary
with one or more independent variables.
• It carries information that helps to make a
useful decisions.
• Types of signal are continuous time signal and
discrete time signal.
• To demonstrate this in MATLAB we use:
– Plot(x,y)
– Stem(n,x)
Creating Simple Plots
Plot the following function in mat lab.
1. y=sin(x), 0<x<2pi
>> x=0:2*pi % defining domain
>>y= sin(x)
>>Plot(x,y)
Continuous-time Signal Example
% Generation of Sine % Generation of cosine
wave wave
t=0:0.1:10; t=0:0.1:10;
x=sin(2*pi*t); x=cos(2*pi*t);
plot(t,x); plot(t,x);
xlabel('Time'); xlabel('Time');
ylabel('Amplitude'); ylabel('Amplitude');
title('Sine wave'); title('Cosine wave');
Exponential Signal Example
%Real valued exponential sequence: a^n
n=-3:5
a1=0.8;
x1=a1.^n;
subplot(1,2,1);
plot(n,x1);
a2=1.2;
x2=a2.^n;
subplot(1,2,2);
plot(n,x2);
Exponential Signal Example
%Real valued exponential sequence a^n
n=-3:5
a1=0.8;
x1=a1.^n;
a2=1.2;
x2=a2.^n;
plot(n,x1,’:’,n,x2,’-’);
legend(‘x1’,’x2’);
Exercise 1
1. Plot the following functions in one figure and use
different colors.
• Annotations
A= sin(2x),0<x<Pi
– xlabel (‘ ‘)
B= cos(4*pi*x), 0<x<2*pi
Hint : – Ylabel (‘ ’)
plot(x, y, ‘color’, ‘shape’)
– title(‘ ’)

– legend(‘ ‘)
Exercise 2
2. % Plotting in 3-D space
x=0:.1:100;
y=cos(x);
z=sin(x);
plot3(x,y,z)
xlabel('x')
ylabel('y=cos(x)')
zlabel('z = sin(x)')
Discrete-time signals
% Generation of Impulse sequence
x=-2:1:2;
y=[0 0 1 0 0];
stem(x,y);
xlabel('Time');
ylabel('Amplitude');
title('Impulse sequence');
Home work
• Try the following MATLAB program and
write the interpretation of each.
report should include :
• Name, ID, Group, subgroup, school, course
title.
• Interpretation on comment section.
• Note: this homework is individual assignment
and holds 10 marks.
Home work 1
1. Plot the following functions in one figure and use
different colors. • Annotations
A= exp(x)+ sin(x)
– xlabel (‘ ‘)
Hint :
plot(x, y, ‘color’, ‘shape’) – Ylabel (‘ ’)

– title(‘ ’)

– legend(‘ ‘)
Homework 2
2. Generate a step sequence and plot the graph.

1, 𝑛𝑛 ≥ 0
𝑢𝑢 𝑛𝑛 = �
0, 𝑛𝑛 < 0
Ans
• X=stepseq(interval)
• y=[zeros(1,10) ones(1,11)];
• unit=n>=0;
Jimma Institute of Technology
School of Biomedical Engineering
Bio-signal Processing Lab.
Experiment 2

Signal Processing in MATLAB


Eden T. and Derartu D.
Experiment objective
• To understand how to implement signal
processing methods in MATLAB.
• To implement folding, shifting and folding of
a given signal in MATLAB.
• To understand how to implement convolution
on MATLAB.
Signal processing
• We perform this processing to determine
• “How much” signal is present
• How long a signal lasts,
• what values the signal takes on,
• To develop measures of signal quality(with
respect to a reference signal)
• To perform signal detection(by determining when
a signal contains useful information rather than
just background noise).
Signal processing

• Shifting : advancing and delaying

• Folding : finding the mirror signal,

• Scaling: increasing amplitude

• Convolution: to relate input with output signal


Shifting Discrete-time Signal
%Shifting a non-function Discrete-time signal
n = 0:8;
x = [0 1 5 2 1 3 6 4 5];
subplot(2,1,1);stem(n,x); title('x(n) signal');
xlabel('n'); ylabel('x(n)');
m=n+2; y=x;% delayed signal
subplot(2,1,2);stem(m,y); title('y(n)=x(n+2)
signal');
xlabel('n'); ylabel('y(n)');
Folding A Discrete-time Signal
% Folding discret- time signal
n=0:8,
x=[0 0 1 2 3 4 5 4 3];
subplot(2,1,1);
stem(n,x);
title('x(n) signal');
m=-fliplr(n);
y=fliplr(x);
subplot(2,1,2);
stem(m,y);
title('y(n)=x(-n) signal')
Convolution
Discrete time systems: convolution
• MATLAB does provide a built-in function
called conv that computes the convolution
between two finite-duration sequences.
• The conv function assumes that the two
sequences begin at n=0 and is invoked by
y = conv (x, h);
Convolution
• While convolving two elements, there are 3 different
key words in Mat-lab which are used to determine the
timing information of the final result y(n). Thus
words are:
– y(n)=conv(x , h, ‘same’) % to get the same timing with the
input x.

– y(n)=conv(x , h, ‘full’) % to get the total timing


Convolution
t=0:.01:5;
h1=ones(size(t));
h2=2*exp(-2*t);
y=conv(h1,h2);
plot(0:.01:10,y);
title('h_1(t)*h_2(t)')
Linear Convolution
%generate the linear convolution
x=input('enter the input sequence:');
n1=input('enter the input sequence interval:');
h=input('enter the impulse response:');
n2=input('enter the impulse response interval:');
subplot(2,2,1)
stem(n1,x);
xlabel('time');
ylabel('amplitude');
title('input sequence');
subplot(2,2,2)
stem(n2,h);
Linear Convolution
xlabel('time');
ylabel('amplitude');
title('impulse response');
subplot(2,1,2)
n=min(n1)+min(n2):1:max(n1)+max(n2);
y=conv(x,h);
stem(n,y);
xlabel('time');
ylabel('amplitude');
title('linear convolution');
disp(x);
disp(h);
disp(y);
Linear Convolution
COMMAND WNDOW
Enter the input sequence:[1 2 3 2]
Enter the input sequence interval:0:1:3
Enter the impulse response:[2 3 1 2]
Enter the impulse response interval:-1:1:2
Exercise 1
1. Given the following two sequences
• Determine the convolution y(n)=x(n)∗h(n) and
plot x(n), h(n) and y(n) in one figure.
NB: the range of y(n) will be [xi+hi : xf+hf ]
Exercise
n1=-3:1:3;
n2=-1:1:4;
n3=-4:1:7;
x = [3, 11, 7, 0, -1, 4, 2];
h = [2, 3, 0, -5, 2, 1];
subplot (2,3,1);
stem(n1,x);
title('input sequence');
subplot (2,3,2);
stem(n2,h);
title('impulse sequence');
subplot (2,3,3);
y = conv(x, h);
stem(n3,y);
title(‘convolution of input and impulse');
Home work
• Try the following MATLAB program and
write the interpretation of each.
report should include :
• Name, ID, Group, subgroup, school, course
title.
• Interpretation on comment section.
• Note: this homework is individual assignment
and holds 10 marks.
Home Work 1
1. Plot the following Complex exponential
signal and write the interpretation.
n=-10:10;
w=0.8;
x=exp(j*w*n);
plot(n,real(x));
plot(n,imag(x));
Home Work 2
2. Compute the following convolution in MATLAB and write the
interpretation.
t=0:.01:5;
x=ones(size(t));
h1=1/pi*t;
y1=conv(h1,x)*.01;
h2=2*exp(-2*t);
th2=5.01:.01:10;
hh2=zeros(size(th2));
h2=[h2 hh2];
y=conv(h2,y1);
plot(0:.01:20,y);
title('h_2(t)*(h_1(t)*x(t))'
Lab. Report Guideline
• You are expected to submit Lab reports for each
experiment you performed.
• Your lab. report should include:
– Name, ID, Group, subgroup, school, course title.
– Objective of the experiment.
– Short introduction about the software used and
background concepts of the experiment.
– MATLAB Code.
– Interpretation of each line on comment section.
– You must publish your code and outputs.
• Note: un published codes will be considered as you
did not perform the experiment at all.

You might also like