band‐pass filtering and the hilbert transform

51
Bandpass filtering and the Hilbert transform Computational Psychiatry Seminar, Signal Processing 2015 Jakob Heinzle [email protected] Translational 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.

Upload: lytu

Post on 04-Jan-2017

239 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Band‐pass filtering and the Hilbert transform

Band‐pass filtering and the Hilbert transform

Computational Psychiatry Seminar, Signal Processing 2015

Jakob [email protected] 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.

Page 2: Band‐pass filtering and the Hilbert transform

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

Page 3: Band‐pass filtering and the Hilbert transform

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)

Page 4: Band‐pass filtering and the Hilbert transform

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

Page 5: Band‐pass filtering and the Hilbert transform

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

Page 6: Band‐pass filtering and the Hilbert transform

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

Page 7: Band‐pass filtering and the Hilbert transform

A simple example – cosine function

Filtering and Hilberting of EEG data 7

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

Analytic signal of Mcos 𝜔𝜔𝑡𝑡 is:

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

Page 8: Band‐pass filtering and the Hilbert transform

Brief recap: Complex numbers

Filtering and Hilberting of EEG data 8

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

Page 9: Band‐pass filtering and the Hilbert transform

Simple matlab demo

Filtering and Hilberting of EEG data 9

So, how does this look like?

Page 10: Band‐pass filtering and the Hilbert transform

Movie illustration

Filtering and Hilberting of EEG data 10

Page 11: Band‐pass filtering and the Hilbert transform

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:

Page 12: Band‐pass filtering and the Hilbert transform

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()

Page 13: Band‐pass filtering and the Hilbert transform

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!!!

Page 14: Band‐pass filtering and the Hilbert transform

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.

Page 15: Band‐pass filtering and the Hilbert transform

Hilbert questions – The audience

Filtering and Hilberting of EEG data 15

Page 16: Band‐pass filtering and the Hilbert transform

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

Page 17: Band‐pass filtering and the Hilbert transform

Filtering is nothing but averaging

Filtering and Hilberting of EEG data 17

Page 18: Band‐pass filtering and the Hilbert transform

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.

Page 19: Band‐pass filtering and the Hilbert transform

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

Filtering and Hilberting of EEG data 19

Page 20: Band‐pass filtering and the Hilbert transform

Illustration of fourier and filtering

Filtering and Hilberting of EEG data 20

Page 21: Band‐pass filtering and the Hilbert transform

Filtering via the Fourier transform – ERP example

Filtering and Hilberting of EEG data 21

Page 22: Band‐pass filtering and the Hilbert transform

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

Page 23: Band‐pass filtering and the Hilbert transform

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.

Page 24: Band‐pass filtering and the Hilbert transform

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

Page 25: Band‐pass filtering and the Hilbert transform

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?

Page 26: Band‐pass filtering and the Hilbert transform

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

Page 27: Band‐pass filtering and the Hilbert transform

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

Page 28: Band‐pass filtering and the Hilbert transform

Comparing filtering and Morlet wavelets

Filtering and Hilberting of EEG data 28

Page 29: Band‐pass filtering and the Hilbert transform

Notch filters

Filtering and Hilberting of EEG data 29

Page 30: Band‐pass filtering and the Hilbert transform

Low pass filters

Filtering and Hilberting of EEG data 30

Page 31: Band‐pass filtering and the Hilbert transform

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.

Page 32: Band‐pass filtering and the Hilbert transform

High pass filter

Filtering and Hilberting of EEG data 32

Page 33: Band‐pass filtering and the Hilbert transform

Causal vs. non-causal filters

Filtering and Hilberting of EEG data 33

Page 34: Band‐pass filtering and the Hilbert transform

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.

Page 35: Band‐pass filtering and the Hilbert transform

Designing filters with Matlab(with firls)

Filtering and Hilberting of EEG data 35

Page 36: Band‐pass filtering and the Hilbert transform

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!

Page 37: Band‐pass filtering and the Hilbert transform

But let’s do some filtering in Matlab

Filtering and Hilberting of EEG data 37

Page 38: Band‐pass filtering and the Hilbert transform

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:

Page 39: Band‐pass filtering and the Hilbert transform

Band pass

Filtering and Hilberting of EEG data 39

Page 40: Band‐pass filtering and the Hilbert transform

Band stop

Filtering and Hilberting of EEG data 40

Page 41: Band‐pass filtering and the Hilbert transform

High pass

Filtering and Hilberting of EEG data 41

Page 42: Band‐pass filtering and the Hilbert transform

Low pass

Filtering and Hilberting of EEG data 42

Page 43: Band‐pass filtering and the Hilbert transform

Look at your filters …

Filtering and Hilberting of EEG data 43

Page 44: Band‐pass filtering and the Hilbert transform

… 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

Page 45: Band‐pass filtering and the Hilbert transform

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

Page 46: Band‐pass filtering and the Hilbert transform

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

Page 47: Band‐pass filtering and the Hilbert transform

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

Page 48: Band‐pass filtering and the Hilbert transform

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!

Page 49: Band‐pass filtering and the Hilbert transform

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

Page 50: Band‐pass filtering and the Hilbert transform

Filter questions – The audience

Filtering and Hilberting of EEG data 50

Thank you for your attention!

Page 51: Band‐pass filtering and the Hilbert transform

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.