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

Curs 5 1 Monitorizare 2014

The document discusses importing and processing an ECG signal recorded at 200 Hz sampling frequency. It loads the ECG data from a file called "ecg1.dat", defines a time vector based on the sampling frequency, and plots the ECG signal versus time for visualization. Basic operations are demonstrated for importing, defining parameters, and plotting a recorded ECG signal in MATLAB.

Uploaded by

Andrushka Ltz
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)
30 views

Curs 5 1 Monitorizare 2014

The document discusses importing and processing an ECG signal recorded at 200 Hz sampling frequency. It loads the ECG data from a file called "ecg1.dat", defines a time vector based on the sampling frequency, and plots the ECG signal versus time for visualization. Basic operations are demonstrated for importing, defining parameters, and plotting a recorded ECG signal in MATLAB.

Uploaded by

Andrushka Ltz
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/ 15

Curs 5

C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
Noiuni de baz de statistic i probabilitate utile
n prelucrarea semnalelor
Valoare medie
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
Deviatie medie
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
Histograme
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
Matlab
Modelare zgomot cu date aleatoare
>> u_n = -5+10*rand(1,1e6);
>> hist(u_n,100)
>> g_n = 10+5*randn(1,1e6);
>> hist(g_n,100)
Uniform
Gaussian
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
Matlab
Adaugare semnal zgomot la semnal
noisy signal = signal + noise
>> y1 = x + rand(size(x)) zgomot uniform
>> y2 = x + randn(size(x)) zgomot Gaussian
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
Exemplu
%Esantionare
Fs = 1000; %frecventa de esantionare
Ts = 1/ Fs; %perioada de esantionare
%Genereaza vectorul timp
t = 1: Ts: 2- Ts;
%Componentele semnalului util
F = 1; %frecveta [Hz]
A = 1; %amplitudine
%Se introduce semnalul de prelucrat:
semnal = A*si n( 2*pi . *t . *F) ; %semnal util sinusoidal
%Semnal zgomot
F_Zgomot = 50; %frecventa [Hz]
A_Zgomot = 0. 25; %amplitudine
zgomot = A_Zgomot *si n( 2*pi . *t . * F_Zgomot ) ;
%Atasare semnalului de zgomot la semnalul util
semnal _zgomot = semnal + zgomot ;
%Afisare semnale
f i gur e( ) ; subpl ot ( 3, 1, 1) ; pl ot ( t , semnal ) ;
xl abel ( 'timp [s]' ) ; yl abel ( 'amplitudine') ; gr i d
t i t l e( 'Semnal original') ;
subpl ot ( 3, 1, 2) ; pl ot ( t , zgomot ) ;
xl abel ( 'timp [s] ' ) ; yl abel ( 'amplitudine') ; gr i d
t i t l e( 'Semnal zgomot') ;
subpl ot ( 3, 1, 3) ; pl ot ( t , semnal _zgomot ) ;
xl abel ( 'timp [s]' ) ; yl abel ( 'amplitudine') ; gr i d
t i t l e( 'Semnal original +zgomot') ;
1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2
-1
0
1
timp [s]
a
m
p
l
i
t
u
d
i
n
e
Semnal original
1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2
-0.5
0
0.5
timp [s]
a
m
p
l
i
t
u
d
i
n
e
Semnal zgomot
1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2
-2
0
2
timp [s]
a
m
p
l
i
t
u
d
i
n
e
Semnal original + zgomot
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
%-----------------------------------------------------------------------------------------------------------------------------
%Semnalul original, reprezentare in timp
%-----------------------------------------------------------------------------------------------------------------------------
T_semnal = 1; %[s], perioada semnalului
Ts = 0.001; %[s], perioada de esantionare
t = 0:Ts:T_semnal-Ts; %genereaza vectorul timp
y = sin(2*pi*50*t); %semnalul original, esantionat
n = length(y); %dimensiunea semnalului
%Genereaza un zgomot cu amplitudinea de ~10%din amplitudinea semnalului, avand valoarea %medie zero
ampl_noise = 0.1;
noise = ampl_noise * (rand(1,length(y)) * 2 - 1);
ny = y + noise; %semnalul cu zgomot adaugat
%-----------------------------------------------------------------------------------------------------------------------------
%Calculul transformatei Fourier
%-----------------------------------------------------------------------------------------------------------------------------
Y = fft(y); %transf. Fourier a semnalului fara zgomot
nY = fft(ny); %transf. Fourier a semnalului cu zgomot
%Amplitudinea spectrului
amp_spec = abs(nY)/(n/2); % n/2 deoarece jumatate sunt complex conjugate
%-----------------------------------------------------------------------------------------------------------------------------
%Reprezentare grafica in timp si frecventa
%-----------------------------------------------------------------------------------------------------------------------------
figure(1);
%Traseaza semnalul cu zgomot, in timp
%-----------------------------------------------------------------------------------------------------------------------------
subplot(2,1,1);
plot(t, ny); grid on;
xlabel('timp [s]'); ylabel('amplitudine')
title('Semnalul cu zgomot in timp si in frecventa');
%Traseaza spectrul semnalului cu zgomot
%-----------------------------------------------------------------------------------------------------------------------------
subplot(2,1,2);
f = (0:1:n-1)/T_semnal; %genereaza vectorul frecventa
plot(f, amp_spec); grid on;
xlabel('frecventa [Hz]'); ylabel('amplitudine');
% Traseaza spectrul semnalului fara zgomot, si cel al semnalului cu zgomot, pentru comparatie
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
Continuare ex 3.9
% Traseaza spectrul semnalului fara zgomot, si cel al semnalului cu zgomot, pentru comparatie
%-----------------------------------------------------------------------------------------------------------------------------
figure(2);
subplot(2,1,1);
amp_spec = abs(Y)/(n/2);
plot(f, amp_spec); grid on;
title('Traseaza spectrul semnalului fara zgomot, si cel al semnalului cu zgomot');
subplot(2,1,2);
amp_spec = abs(nY)/(n/2);
plot(f, amp_spec); grid on;
%-----------------------------------------------------------------------------------------------------------------------------
%Filtrare semnal cu ajutorul transf. Fourier inverse
%-----------------------------------------------------------------------------------------------------------------------------
%in spectrul semnalului cu zgomot, anuleaza toate punctele pentru care amplitudinea este mai
%mica decat o valoare prestabilita, ampl_min
ampl_min = ampl_noise;
for k = 1:n
if abs(nY(k))/(n/2) < ampl_min
Y_f(k) = 0;
else
Y_f(k) = nY(k);
end
end
iY_f = ifft(Y_f); %calculeaza transf. inversa a semnalului modificat, "filtrat"
y_f = real(iY_f); %pastreaza doar partea reala
%-----------------------------------------------------------------------------------------------------------------------------
%Semnalul filtrat reprezentat in timp si in frecventa
%-----------------------------------------------------------------------------------------------------------------------------
figure(3);
%Reprezentare in timp
subplot(2,1,1);
plot(t, y_f); grid on
xlabel('timp [s]'); ylabel('amplitudine');
title('Semnalul filtrat reprezentat in timp si in frecventa');
%Reprezentare in frecventa
subplot(2,1,2);
amp_spec = abs(Y_f)/(n/2);
plot(f, amp_spec); grid on; xlabel('frecventa [Hz]'); ylabel('amplitudine');
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
textread
xlsread
imread
importdata
wavread
uiimport
Import Date
in Matlab
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
Exemplu
cl ear al l % sterge toate variabilele active
cl ose al l
%%Permite incarcarea pe rand a fisierului ECG dorit %%
% Afiseaza in fereastra Command Window va apare mesajul dintre apostrof :
f nam= i nput ( ' I nt r oducet i numel e f i si er ul ui ECG : ' , ' s' ) ;
f i d = f open( f nam) ;
ecg = f scanf ( f i d, ' %f ' ) ;
f s = 200; % frecventa de esantionare
l ungi me_semnal = l engt h( ecg) ;
n_ecg = ecg/ max( ecg) ; % valoarea maxima a amplitudinii e normalizata la unitate
t = [ 1: l ungi me_semnal ] / f s; % genereaza vectorul timp
f i gur e;
pl ot ( t , n_ecg) ;
axi s t i ght ;
yl abel ( ' semnal ECG' ) ; xl abel ( ' t i mp [ sec] ' ) ;
La rularea codului Matlab n fereastra Command Window apare mesajul:
Se introduce numele fisierului ECG : ..
2 4 6 8 10 12 14 16 18 20
0.5
0.6
0.7
0.8
0.9
1

s
e
m
n
a
l

E
C
G
timp [sec]
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
Exemplu
File / Import Data File / Import Data
ex: ECG_I+II+III.xls ex: ECG_I+II+III.xls
Din Din Workspace Workspace se selecteaza semnalul de prelucrat si se selecteaza semnalul de prelucrat si
se salveaza se salveaza - - Save as Save as cu extensia cu extensia .mat .mat
Dublu clic pe fisierul Dublu clic pe fisierul ECG.mat ECG.mat actual creat. actual creat.
Se ruleaza programul m Se ruleaza programul m- -file file
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
Apl2. Se consider un semnal ECG
achiziionat cu frecventa de
esantionare fs =200 Hz. Semnalul
este stocat n fisierul cu numele
ecg1.dat.
cl ear al l % sterge variabilele active
cl ose al l
ecg = l oad( ' ecg1. dat ' ) ; % incarca semnalul in variabila ecg
f s = 200; % frecventa de
esantionare [Hz]
l ungi me_semnal = l engt h( ecg) ;
t =[ 1: l ungi me_semnal ] / f s; %
defineste vectorul timp
f i gur e
pl ot ( t , ecg)
xl abel ( ' t i mp [ sec] ' ) ; yl abel ( ' Semnal ECG' ) ;
axi s t i ght ;
Exemplu
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 2.2
-0.5
0
0.5
1
1.5
2
2.5
timp [sec]
S
e
m
n
a
l
E
C
G
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
Semnal & Sistem
(DEF) Semnal (recapitulare): Un semnal este definit
formal ca o functie de una sau mai multe variabile,
care furnizeaza informatii despre natura unui
fenomen fizic.
(DEF) Sistem : Sistemul este definit formal ca o
entitate care manipuleaza unul sau mai multe
semnale pentru a indeplini o functie, rezultand astfel
noi semnale.
sistem
semnal
iesire
semnal
intrare
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
Biomedical system (biomedical signal
processing)
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m
C
lic
k
to
b
u
y
N
O
W
!
P
D
F-XChang
e
w
w
w
.d
oc u-t r ac k
.c
o
m

You might also like