finding best wavelet basis for epileptic stage differentiation ● the goal is to find a pair of...

25
Finding best wavelet Finding best wavelet basis for epileptic basis for epileptic stage differentiation stage differentiation The goal is to find a pair of filters which can reliably detect pre-preictal (i.e. Several hours before the onset of seizure) and preictal (i.e. Less then half an hour prior to onset of seizure( Such filters would be used to serve an early warning for seizure onset, by analyzing a particular EEG signal from a single electrode (more formally a single

Upload: shon-quinn

Post on 27-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Finding best wavelet basis for Finding best wavelet basis for epileptic stage differentiationepileptic stage differentiation

● The goal is to find a pair of filters which can reliably detect pre-preictal (i.e. Several hours before the onset of seizure) and preictal (i.e. Less then half an hour prior to onset of seizure(

● Such filters would be used to serve an early warning for seizure onset, by analyzing a particular EEG signal from a single electrode (more formally a single differential of two electrodes(

Signal analysis – backgroundSignal analysis – background

● Several methods exist for detecting features in discrete signal.

● One such method is a Fourier transform, in particular the DFT (Discrete Fourier Transform), which has an efficient numeric implementation known as FFT (Fast Fourier Transform)

● Another widespread family of transforms are wavelet transforms.

Transforms temporal signal representation into frequency domain – each ”finite-power” signal can be represented as a linear combination of scalings of sine and cosine functions. Those scalings correspond to the different frequencies.

Fourier transformFourier transform

Fourier – exampleFourier – example

Fourier (only real part)

Fourier transform - limitationsFourier transform - limitationsProvides no temporal localization of detected features. (i.e. If the

function has a discontinuity it is possible to see it in the frequency domain, however it is impossible to deduce where is it in the time domain)

Gibb's phenomena – the inability to precisely describe discontinuous functions: for instance the following are approximations for square wave:

5 approx. steps 25 approx. steps 125 approx. Steps. The maximal difference is still the same (non-

uniform convergence)

Wavelet transformsWavelet transforms

A family of transforms based on the notion of a scaling function and a wavelet function, from which the basis of L

2(R) is

ultimately derived. (by scaling and shifting the wavelet function)

Another way to look at the tranform is from the point of view of MRA. (Multi-resolution analysis)

Wavelets - MRAWavelets - MRA

The wavelet basis can also be derived from two following recurrences:

These are relations which define the scaling and the wavelet function, respectively. In fact it can be proven that these functions can be uniquely derived from {h

k} and {g

l}. If these sets furthermore satisfy

certain conditions then the result is an orthogonal basis.

Znnnn

Znnnn

ntgtg

nthth

22,

22,

,10,0

,10,0

Wavelets – contWavelets – cont..

If the {hk} and {g

l} are finite, then we

have wavelets with finite support. Those allow for simpler numerical computations

Wavelets vs. Fourier analysisWavelets vs. Fourier analysis

Wavelets allow the inspection of local behaviours of a signal. (this is because each wavelet coefficient is affected only by a finite support, depending on the scale)

Wavelets allow for MRA – localizing the analysis if required, or looking at more general properties of a signal as Fourier does. Wavelets allow building arbitrary level (subject to scale limitations) of ”approximation” of the signal between the most crude (expressed by only scaling-coefficients) and the most accurate (the signal itself, represented by full dyadic decomposition)

Wavelets vs. Fourier analysisWavelets vs. Fourier analysis

Wavelets allow one to inspect only fixed set of frequencies (scales) if dyadic decomposition is used or result in excessive information (doubling the dimension!) if continuous wavelet transform is used. There are plenty of compromises between these two approaches, though.

(We limit ourselves here to orthonormal wavelet bases, though there are transform variations which do not require orthonormality)

EntropyEntropy● In information theory , entropy is a

measure of the uncertainty associated with random variable. The entropy rate of a data source means the average number of bits per symbol needed to encode it

● p denotes the probability mass function of X● I(X) is the information content

Entropy based best basisEntropy based best basis

The best basis algorithm purpose is to select the most ”meaningful” basis for a signal representation. That, a set of filters such as the resulting coefficient convey real information, and not stay fixed during the whole signal duration. (The most ”informative” signal according to the entropy function is one whose coefficients are distributed uniformly across temporal shifts of the signal)

Tree of orthonormal basesTree of orthonormal bases

1.Subset of basis vectors can be identified with intervals of N of form

2.Each basis in the library corresponds to a disjoint cover of N by intervals

3.If is the subspace identified with Then

0,)1(2,2 knnnI kknk

nkI

knV , nkI knknkn VVV ,12,21,

0,70,60,50,40,30,20,10,0

1,31,21,11,0

2,12,0

3,0

IIIIIIII

IIII

II

I

Selecting the best basisSelecting the best basis

Orthonormal tree search for best basis by induction . Donate Bn,k the basis of signal corresponding to Ink , and An,k the best basis for the same interval, For K=0 ther is single basis (An,0 = Bn,0).

For K>0,

*E – entropy , but can be any additive cost function

woxAxA

xAExAExBEifBA

knkn

knknknknkn .

)()()(

,12,2

,12,21,1,1,

Code exampleCode examplefunction [ output_args ] = sd1( input_args )%SD1 find best basis coefficent, find and print best basis tree % gnerate best basis from 50% overlapping windows of size s signal=input_args; s=2048; %define window size 2^(k), k =1,2,3.... count=0; mean_coff_tree= zeros(s,log2(s)+1); %run over 50% overlapping window and sum cofficent while length(signal)>(s-1) cur_window=signal(1:s); signal=signal((s/2+1):length(signal)); %get cofficent for single window cof_tree=find_coff(cur_window); mean_coff_tree=mean_coff_tree+cof_tree; count=count+1 end %calculate mean of output_args=mean_coff_tree./count; titlestr = 'test'; D=log2(s); %Build tree with entropy numbers output_args= CalcStatTree(output_args,'Entropy'); [btree,vtree] = BestBasis(output_args,D); signaltitle = [' CP Best Basis; ' titlestr]; hold on PlotBasisTree(btree,D,output_args,signaltitle); xlabel('Splits of Time Domain') ylabel('Entropy Drop')return

function [ output_args ] = find_coff( input_args )%FIND_COFF find cofficet of input D=log2(length(input_args)); %Generate Orthonormal QMF

(quadrature mirror filter) %for Wavelet Transform

qmf = MakeONFilter('Haar');

%output array of Wavelet Packet Decompositions %Coefficients for frequency interval % [b/2^d,(b+1)/2^d] is stored in wp(packet(d,b,n),d+1) cof_tree=WPAnalysis(input_args,D,qmf); output_args=cof_treereturn

OutputOutput

Function usage for very short Function usage for very short signalsignalsignal = [3 4 6 6 4 4 1 1]

%Generate Orthonormal QMF (quadrature mirror filter) %for Wavelet TransformInput>> qmf = MakeONFilter('Haar')

output>> qmf = 0.7071 0.7071

%output array of Wavelet Packet Decompositions %Coefficients for frequency interval% [b/2^d,(b+1)/2^d] is stored in wp(packet(d,b,n),d+1)Input>> cof_tree=WPAnalysis(pre1,3,qmf)Output>> cof_tree =

3.0000 4.9497 9.5000 10.2530 4.0000 8.4853 5.0000 -3.1820 6.0000 5.6569 2.5000 -3.8891 6.0000 1.4142 -3.0000 -0.3536 4.0000 0.7071 -0.5000 -0.3536 4.0000 0 0 0.3536 1.0000 0 0.5000 -0.3536 1.0000 0 0 0.3536

%Build tree with entropy numbers Input>> entrophy_val=CalcStatTree(cof_tree,'Entropy')

Output >> entrophy_val =

Columns 1 through 5

1.7388 1.0507 0.0213 0.5728 0.3291

Columns 6 through 10

0.0119 0.0119 0.1766 0.1979 0.2493

Columns 11 through 15

0.0066 0.0066 0.0066 0.0066 0.0066

Relatet to 1 depth decomposionRelatet to 2 depth decomposionRelatet to 3 depth decomposionRelatet to 4 depth decomposion

Short signal - First step exampleShort signal - First step example

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.90

5

10very short signal

1 2 3 4 5 6 7 80

5

101.738765

1 2 3 4 5 6 7 80

5

101.050656 , 0.021253

1 2 3 4 5 6 7 8-10

0

100.572797 , 0.329146, 0.011949, 0.011949

1 2 3 4 5 6 7 8-20

0

200.176584 , 0.197877, 0.249256, 0.006636, 0.006636 , 0.006636, 0.006636, 0.006636

Origin signal

D1 coefficients

D2coefficients

D3coefficients

D4coefficients

***Numbers upon subsets are correlated entropy values

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1.8

-1.6

-1.4

-1.2

-1

-0.8

-0.6

-0.4

-0.2

0Basis Tree: Best Basis

Best basis for 2048 samples length signalBest basis for 2048 samples length signal

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

-1000

0

1000

2000

prepreictal full signal

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

-100

0

100

200

prepreictal first window of size 2048

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-4

-3

-2

-1

0Basis Tree: first window

function [ output_args ] = OneWin( input_args )%finding the best basis tree for one window subj= load('Subject1/subj1_data_seizure1');p_pre=subj.pre_preictal;p_pre1=p_pre(1,:); n = length(p_pre1)t = (0:(n-1))./n;figure;subplot(3,1,1);plot(t,p_pre1);title('pre_preictal full signal'); w_size=2048; n=w_size; t = (0:(n-1))./n; D=log2(w_size) subplot(3,1,2);plot(t,p_pre1(1:w_size));title('pre_preictal first window of size 2048'); qmf = MakeONFilter('Haar'); cof_tree=WPAnalysis(p_pre1(1:w_size),D,qmf);output_args= CalcStatTree(cof_tree,'Entropy'); [btree,vtree] = BestBasis(output_args,D); subplot(3,1,3); signaltitle = ['first window'];PlotBasisTree(btree,D,output_args,signaltitle); returnend

Step by step (middle step)Step by step (middle step)

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

-100

-50

0

50

100

150 1 - 2048 sampels

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-100

0

100

1-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-100

0

100

2-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-100

0

100

3-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-100

0

100

4-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-4

-3

-2

-1

0Basis Tree:

Step 1. The signal

Step 2. Find coeffients for all decomposition Step 3. Find best basis

The relation for this resoulation can be clearly seen,For right side of the signal high level decomposition hold more information

Finding the mean coefficients Finding the mean coefficients (start)(start)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

1-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

2-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

3-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

4-s decompostion coeffients

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

-100

-50

0

50

100

150 3073 - 5120 sampels

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

-100

-50

0

50

100

150 2049 - 4096 sampels

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

-100

-50

0

50

100

1501025 -3072 sampels

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

-100

-50

0

50

100

150 1 - 2048 sampels

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

1-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

2-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

3-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

4-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

1-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

2-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

3-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

4-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

1-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

2-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

3-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

4-s decompostion coeffients

Find all decomposions Coeffients for each of the 50% overlap window

separately

Finding the mean coefficients Finding the mean coefficients (cont)(cont)

• To find mean derived best basis, we run over 50% overlapping windows , for each window, find stat tree and add it to the sum tree, also we count number of windows included.

• At the end off the this process we divide each of the n*logn coefficient with the counter and we got mean coefficients tree.

• To find std tree, we run over the signal for the second time , again find stat tree for each window, and use the mean coefficients we already got to find std for each one of the n*logn coffcients.

see code at next two slides

Best Basis mean Derived Best Basis mean Derived (cont’)(cont’)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

1-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

2-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

3-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

4-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

1-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

2-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

3-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

4-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

1-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

2-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

3-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

4-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

1-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

2-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

3-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

4-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

1-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

2-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

3-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1000

100

4-s decompostion coeffients

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-7

-6

-5

-4

-3

-2

-1

0Basis Tree: CP Best Basis; test

Splits of Time Domain

Entr

opy D

rop

Generate mean coefficients for each decomposition

Fined best basis tree for mean coefficients

mean_coff_tree= zeros(s,log2(s)+1);

%run over 50% overlapping window and sum cofficent

while length(signal)>(s-1) cur_window=signal(1:s); signal=signal((s/2+1):length(signal)); %get n*logn coefficient for single window cof_tree=find_coff(cur_window); %get n*logn sums of cofficents mean_coff_tree=mean_coff_tree+cof_tree; count=count+1 end %calculate mean of mean_coff_tree=mean_coff_tree./count;

%get best basis for the mean coefficient m_stat_tree=CalcStatTree(mean_coff_tree,'Entropy'); [btree,vtree] = BestBasis(m_stat_tree,D);

Find STD treeFind STD tree count=0;

std_coff_tree= zeros(s,log2(s)+1);

%run over 50% overlapping window and sum cofficent

while length(signal)>(s-1)

cur_window=signal(1:s);

signal=signal((s/2+1):length(signal));

%get n*logn coefficient for single window

cof_tree=find_coff(cur_window);

%get n*logn of squr diff for single window

std_tree=(cof_tree-m_cof_tree).^2;

%get n*logn sums of squr diff

std_coff_tree=std_coff_tree+std_tree;

count=count+1;

end

%calc n*logn std

std_coff_tree=sqrt(std_coff_tree/count)

Using Using WAVELAB 850WAVELAB 850

A partial list of the techniques made available:• orthogonal and biorthogonal wavelet transforms,• translation-invariant wavelets,• interpolating wavelet transforms,• cosine packets,• wavelet packets,• matching pursuit,

Library used for first part• Wavelab850\Orthogonal library

◦ routines in this directory perform periodic- and boundary-corrected wavelet analysis of 1-d and 2-d signals.

• Wavelab850\Packets\One-D library◦ routines in this directory perform wavelet packet analysis and cosine packet analysis of 1-d signals.