band‐pass filtering and the hilbert transform

Post on 04-Jan-2017

240 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Band‐pass filtering and the Hilbert transform

Computational Psychiatry Seminar, Signal Processing 2015

Jakob Heinzleheinzle@biomed.ee.ethz.chTranslational Neuromodeling Unit (TNU) Institute for Biomedical Engineering (IBT)University and ETH Zürich

Translational Neuromodeling Unit

All images (unless referenced otherwise) are from Chapter 14 of MX Cohen’s book and Chapter 12 of S Luck’s book.

Looking at brain music?

Filtering and Hilberting of EEG data 2

We want to understand brain signals!

A very useful way to look at brain signals is to represent the signal in frequency space –analogous to oscillations with a frequency, amplitude (power) and phase (lag).

Adapted from slides by F. Petzschner

What have we done so far?

• Fourier Transform: Representation in frequency space

Temporal resolution completely lost.

Filtering and Hilberting of EEG data 3

• Morlet Wavelets: Complex representation of signal

analytical signal

Frequency information (not so precise)

Temporal resolution (not so precise)

Overview

• Introduction to Hilbert transform and analytic function

• Examples and intuition about the Hilbert transform

• Introduction to filtering• Examples and intuition about filtering and

interpretation of filtered data.

Filtering and Hilberting of EEG data 4

Hilbert transform

• Hilbert Transform: Allows for extension of signal into

complex plane.

Analytic signal that has both amplitude and phase.

Powerful tool together with filtering

Filtering and Hilberting of EEG data 5

What does the Hilbert transform do?Why do we want to use it?

• Extends a real valued signal to the complex plan, by adding a complex part.

For the math lovers: It’s the unique (up to a constant) extension of a real valued signal to a holomorphic (Cauchy-Riemann criterion) function.

• Having a complex valued function is useful because many mathematical details are much easier, e.g., reading the phase and amplitude information (c.f. Wavelet lecture)

• The Hilbert transform does not add anything new to the data, all could be done with real valued methods as well.

Filtering and Hilberting of EEG data 6

A simple example – cosine function

Filtering and Hilberting of EEG data 7

𝐻𝐻 cos(𝜔𝜔𝑡𝑡) = sin(𝜔𝜔𝑡𝑡)

Analytic signal of Mcos 𝜔𝜔𝑡𝑡 is:

Mcos(ωt) + iMsin(𝜔𝜔𝑡𝑡)

Brief recap: Complex numbers

Filtering and Hilberting of EEG data 8

http://betterexplained.com/articles/a-visual-intuitive-guide-to-imaginary-numbers/

Simple matlab demo

Filtering and Hilberting of EEG data 9

So, how does this look like?

Movie illustration

Filtering and Hilberting of EEG data 10

Math slide 1: Hilbert transform

Filtering and Hilberting of EEG data 11

𝐻𝐻 𝑢𝑢 (𝑡𝑡) =1𝜋𝜋𝑝𝑝. 𝑣𝑣. �

−∞

∞𝑢𝑢(𝜏𝜏)𝑡𝑡 − 𝜏𝜏

𝑑𝑑𝜏𝜏

𝐻𝐻 𝐻𝐻 𝑢𝑢 𝑡𝑡 = −𝑢𝑢(𝑡𝑡)

Definition:p.v. (Cauchy principle value)

Some properties:

𝐻𝐻−1 = −𝐻𝐻

Relation to Fourier transform:

ℱ 𝐻𝐻 𝑢𝑢 𝜔𝜔 = (−𝑖𝑖 𝑠𝑠𝑖𝑖𝑠𝑠𝑠𝑠(𝜔𝜔))ℱ 𝑢𝑢 (𝜔𝜔) Method used to calculate H in MX Cohen’s book.

𝑦𝑦 𝑡𝑡 = 𝑢𝑢 𝑡𝑡 + 𝑖𝑖𝐻𝐻[𝑢𝑢](𝑡𝑡)Analytic signal:

Hilbert Summary

Filtering and Hilberting of EEG data 12

• Extends a real valued signal to the complex plan, by adding a complex part.

• Works on the entire signal, but is mostly applied to band-pass filtered data.

• Alternative to wavelets. It allows for more control on the filter properties (although one could create wavelets with the desired filter properties.)

• There is many ways to compute the Hilbert transform in Matlab, e.g. hilbert()

Know what you do and what you expect to happen with (artificial) data

Filtering and Hilberting of EEG data 13

“We regret that there was an error in the analytic code used to compute oscillatory power in our article. Specifically, there was a matrix transposition error in the code (see abs(hilbert(eegfilt(data,Fs,f1,f2))) on page 7588, right column, end of second full paragraph). The data matrix was oriented correctly for the call to eegfilt, but the output of the call to eegfilt was not correctly transposed in the standard Matlab format before passing into the built-in Matlab ‘hilbert’ function, as the EEGLAB function ‘eegfilt’ and the built-in Matlab function ‘hilbert’ require the data matrix to have different dimensions in order to operate correctly across time. … ” (The Journal of Neuroscience, 2015; 35(6): 2838)

Matlab’s hilbert()works on columns,not rows!!!

Hilbert questions – The speaker first

Filtering and Hilberting of EEG data 14

Which of the following statements are true/false or need discussion:• The Hilbert transform increases the

dimensionality of the data.• The Hilbert transform enables analyses

which are otherwise not possible. • The Hilbert transformed data allows us to

easily calculate the “instantaneous” frequency.

Hilbert questions – The audience

Filtering and Hilberting of EEG data 15

Filtering in a nutshell

Why filtering?• Filtering is used to extract/eliminate certain

features from the data. How?• In fact, filtering is nothing but clever

averaging of the signal.

Filtering and Hilberting of EEG data 16

Filtering is nothing but averaging

Filtering and Hilberting of EEG data 17

But, we can be a bit clever about it …

Filtering and Hilberting of EEG data 18

𝑥𝑥𝑓𝑓 𝑡𝑡 = �−𝑡𝑡1

−𝑡𝑡2𝑥𝑥 𝜏𝜏 𝑊𝑊 𝑡𝑡 + 𝜏𝜏 𝑑𝑑𝜏𝜏

𝑥𝑥𝑓𝑓 𝑡𝑡 = �𝑡𝑡1

𝑡𝑡2𝑥𝑥 𝜏𝜏 𝐾𝐾 𝑡𝑡 − 𝜏𝜏 𝑑𝑑𝜏𝜏

Usually the averaging is performed as convolution with a filter kernel K, the so called impulse response function.

… and even more clever (with the help of Monsieur Fourier)

Filtering and Hilberting of EEG data 19

Illustration of fourier and filtering

Filtering and Hilberting of EEG data 20

Filtering via the Fourier transform – ERP example

Filtering and Hilberting of EEG data 21

Math slide 2: Convolutions and filters

Filtering and Hilberting of EEG data 22

𝑥𝑥𝑓𝑓 𝑡𝑡 = �−∞

∞𝑥𝑥 𝜏𝜏 𝐾𝐾 𝑡𝑡 − 𝜏𝜏 𝑑𝑑𝜏𝜏

Convolution with Impulse response function 𝐾𝐾 𝑡𝑡 :

�𝑥𝑥𝑓𝑓 𝜔𝜔 = �𝑥𝑥 𝜔𝜔 �𝐾𝐾 𝜔𝜔Multiplication with Frequency response function �𝐾𝐾 𝜔𝜔 :

Causal filters 𝐾𝐾 𝑡𝑡 = 0 if 𝑡𝑡 < 0

Where ^ denotes the Fourier transform

Sharp edges in one domain, result in a lot of leak in the other domain!! Filter design

Definitions: Length of filter in time

• Finite impulse response (FIR) filter– Restricts the effect of an event, data point, to a

finite time window.

• Infinite impulse response (IIR) filter– Allows for infinite time effects of single events,

data points.

Filtering and Hilberting of EEG data 23

Disclaimer: The term FIR is often used differently in dynamical systems and it might be more correct to adopt the terminology of MX Cohen and talk about.

Time domain filter kernel and Frequency domain filter kernelIn this talk, FIR and filter kernel are used interchangeably.

Definitions: Frequency pass properties

Filtering and Hilberting of EEG data 24

Band stop filterAttenuates intermediate frequencies, lets others pass.

Band pass filterLets intermediate frequencies pass, attenuates others.

High pass filterLets high frequencies pass, attenuates low frequencies.

Low pass filterLets low frequencies pass, attenuates high frequencies

Definitions: Causality

• Causal filters– Ensures causality, i.e., there is no leak of signal into the past. This

means that the impulse response is 0 for negative time.

• Non-causal filters– Does not respect causality, i.e., there can be leak of signal into the past.

This means that the impulse response is non-zero for negative time.

Filtering and Hilberting of EEG data 25

Causal or not?

Definitions: Analog vs. digital

• Analog filters– Filters that are built with electronic circuits, e.g. capacitances, resistors

and solenoids. Analog filters are always causal!

• Digital filters– Filters that are implemented on computer. Are much more flexible and

might be non-causal!

Filtering and Hilberting of EEG data 26

Images: www.wikipedia.org

In the rest of this lecture …

… we will focus on digital, FIR filters and look at different filter properties and causality.

1) We try to develop an intuition for filters.

2) We have a look at some Matlab examples using the firls() function.

Filtering and Hilberting of EEG data 27

Comparing filtering and Morlet wavelets

Filtering and Hilberting of EEG data 28

Notch filters

Filtering and Hilberting of EEG data 29

Low pass filters

Filtering and Hilberting of EEG data 30

Creating a high pass filter in the time domain

Filtering and Hilberting of EEG data 31

Just take the difference between a non-filter (unity) and a low-pass filter.

High pass filter

Filtering and Hilberting of EEG data 32

Causal vs. non-causal filters

Filtering and Hilberting of EEG data 33

Be aware …

Filtering and Hilberting of EEG data 34

Filters can do stuff to yourdata (not all of it very intuitive)

that can influenceyour conclusions.

E.g. about causality.

Designing filters with Matlab(with firls)

Filtering and Hilberting of EEG data 35

What is the best filter?

Filtering and Hilberting of EEG data 36

Filter design is an art on its own. There is no

perfect filter. A chosen filteralways has its pros (hopefully)

and cons (for sure).Filter design is not the topic today!

But let’s do some filtering in Matlab

Filtering and Hilberting of EEG data 37

But let’s do some filtering in Matlab

Filtering and Hilberting of EEG data 38

Amplitude of filter

Define relevant frequencies

Compute IRF and filter data:

Band pass

Filtering and Hilberting of EEG data 39

Band stop

Filtering and Hilberting of EEG data 40

High pass

Filtering and Hilberting of EEG data 41

Low pass

Filtering and Hilberting of EEG data 42

Look at your filters …

Filtering and Hilberting of EEG data 43

… and at the results of your pipeline

• Feed your filtering – Hilbert pipeline with artificial data, where you know what you should get. e.g. the sum of two sinusoids, with one frequency that should be suppressed and one that should pass.

Filtering and Hilberting of EEG data 44

Recipe for an analysis using the Hilbert transform.

• Remove very low and very high frequencies using high and low pass filters.

• For a series of bands use a band pass filter followed by a Hilbert transform to extract instantaneous phase or frequency.

Filtering and Hilberting of EEG data 45

Filtering summary

• Filtering is nothing but clever (weighted) averaging.

• In the Fourier domain, filtering consists of using multiplication to select a suitable set of frequencies.

• Filtering is an art on its own.• Filters can introduce “artefacts”.

Filtering and Hilberting of EEG data 46

Fundamental Principle of Frequency-Based Analyses

Filtering and Hilberting of EEG data 47

“Power at a given frequency does not mean that thebrain was oscillating

at that frequency.”Luck (2014), Chapter 12

Filtering helps “seeing” oscillations

Filtering and Hilberting of EEG data 48

Filtering is like putting on very specific glasses that let through only the red and yellow light – and it will alwaysbe autumn when you look at a forest!

Filter questions – The speaker first

• Does the peak of a waveform change, when applying a symmetrical/causal filter?

• What filter would you use?– if you want to detect the earliest onset of

activity after stimulation– if you want to analyze sleep slow waves (2-5

Hz)

• Does filtering only change the power/amplitude or the phase as well?

Filtering and Hilberting of EEG data 49

Filter questions – The audience

Filtering and Hilberting of EEG data 50

Thank you for your attention!

The last slide

Filtering and Hilberting of EEG data 51

The End

All images (if not referenced otherwise) are from Chapter 14 of MX Cohen’s book and Chapter 12 of S Luck’s book.

top related