WT Slides

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 6

Wavelets

Wave-like oscillation localized in space (time)


−(x − b)2 /(2a2)
−(x − 2na3

b)e
First derivative of
Example: Gaussian Function

Smaller scale Larger scale (stretched)


[1] Two basic (squished)
properties:
• Scale (dilation) - how “stretched”
or “squished” wavelet is (related
to frequency)

Shifted left Shifted right and


• Location - where wavelet is squished

positioned in time
b

[1] Addison, P.S. (2005). Wavelet transforms and the ecg: A review. Physiological Measurement, 26 (5), p.
R155 1
Wavelet Transform
Decomposition of a signal using wavelets of varying scale and location

Basic idea: compute how much of


wavelet is in the signal for a
particular scale and location
i.e. evaluate convolution of signal and wavelet
at varying scales

Why wavelets?
• Traditional Fourier transform (decomposition using sine and cosine) gives global average over
entire signal, thus may obscure local information

• Wavelet transforms can extract local spectral and temporal information simultaneously

• Variety of wavelets to choose from


Addison, P.S. (2005). Wavelet transforms and the ecg: A review. Physiological Measurement, 26 (5), p. R155 2
Wavelet Transform
Two methods
Continuous Wavelet Transform (CWT) Discrete Wavelet Transform (DWT)

“Mother” (basis) wavelets are defined everywhere “Mother” (basis) wavelets are only defined on discrete grid

/ = /(t) / = /m,n(t)

Transform must be discretized for implementation Transform is already discrete!

o o
1 o
T(a, b) =
x(t) /*
(t − b)
dt
o x(t) /m,n(t) dt
a ! −oo a Tm,n =
! −oo

Coefficients (Tm,n) do not have redundant information since


T(a, b) may have redundant information since discretized wavelets can be defined to be orthonormal
same feature may be captured by multiple scales

Addison, P.S. (2005). Wavelet transforms and the ecg: A review. Physiological Measurement, 26 (5), p.
R155 3
clear; close all; clc
Example
Code to use Maximal Overlap Discrete Wavelet Transform
(MODWT) to Analyze ECG Data
Code authored by: Shawhin Talebi

The University of Texas at Dallas

Mutli-scale Integrated Remote Sensing and Simulation (MINTS)

Load Data
load('ECG.mat');

Perform Wavelet Transform


Use the maximal overlap discrete wavelet transform (MODWT) to enhance the R peaks in the ECG waveform.
The MODWT is an undecimated wavelet transform, which handles arbitrary sample sizes.

Perform MODWT for 6 different scales. The rows of wt give the wavelet (detail) coefficents for each scale. Here
we are using Symlets wavelet with 4 vanishing moments

Other wavelet families can be used. use waveletfamilies('f') to view all

% define number of levels to use


numLevels = 6;

% perform maximal overlap discrete wavelet transform (MODWT)


wt = modwt(ECG, 'sym4', numLevels);

Compare Coefficents for all MODWT Scales


% get number of Wavelet Scales
[numScales, ~] = size(wt);

% create figure
fig = figure(1);
fig.Units = 'normalized';
fig.Position = [0 0 1 1];

% plot original signal


subplot(numScales+1,1,1)
plot(ECG, 'r-')
title('Orginal ECG', 'FontSize', 14)
axis tight

% plot wavelet scale coefficents


for i=2:numScales+1

subplot(numScales+1,1,i)
plot(wt(i-1,:))
title(strcat('Wavelet Scale 2/\', string(i-1)), 'FontSize', 14)
axis tight
end 1

xlabel('Time', 'FontSize', 14)

% print figure to file


print('waveletTransform_signal_decomposition', '-dpng'); https://github.com/ShawhinT/YouTube 4
Reconstruct Signal via Inverse MODWT
Example
% create figure
fig figure(2);
fig.Units
'normalized';
fig.Position
[0 0 1 1];

% initialize an array to store the coefficents corresponding to scale


2A4 recwt zeros(size(wt));

% store coefficents corresponding to scale 4 in


array recwt(4,:) wt(4,:);

% reconstruct signal using only scale 4 with inverse


transform recECG imodwt(recwt,'sym4');

% compare original signal and reconstructed


% plot original signal
subplot(2,1,1)
plot(ECG, 'r-')
title('Orginal ECG',
2
'FontSize', 16)
xlabel('Time',
'FontSize', 14)
axis tight
% plot reconstructed signal
subplot(2,1,2)
plot(recECG)
title('Reconstructed ECG', 'FontSize', 16)
xlabel('Time', 'FontSize', 14)
axis tight

% print figure to file


print('waveletTransform_reconstructed_signal', '-dpng')
https://github.com/ShawhinT/YouTube 5
Find R Peaks Using Reconstructed Signal
% define array of time indicies
Example
t 1:length(ECG);

% square reconstructed signal


recECG abs(recECG)."2;
% find peaks in squared
reconstructed signal
[qrspeaks,locs]
findpeaks(recECG, t,
'MinPeakHeight', 0.35,
'MinPeakDistance',100);

% create figure
fig figure(3);
fig.Units 'normalized';
fig.Position [0 0 1 1];

% plot signal with detected r peaks using reconstructed signal from DWT
plot(t,ECG)
hold on
plot(locs,ECG(locs),'ro')
xlabel('Time', 'FontSize', 14)
title('R Peaks Detected Using Reconstructed Signal from Wavelet Transform',
'FontSize', 16)
axis tight
print('waveletTransform_rpeak_annotation', '-dpng')

https://github.com/ShawhinT/YouTube 6

You might also like