Band pass filtering and the Hilbert transform Computational Psychiatry Seminar, Signal Processing 2015 Jakob Heinzle heinzle@biomed.ee.ethz.ch Translational Neuromodeling Unit (TNU) Institute for Biomedical Engineering (IBT) University and ETH Zürich All images (unless referenced otherwise) are from Chapter 14 of MX Cohen s book and Chapter 12 of S Luck s book. Translational Neuromodeling Unit
Looking at brain music? 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 Filtering and Hilberting of EEG data 2
What have we done so far? Fourier Transform: Representation in frequency space Temporal resolution completely lost. Morlet Wavelets: Complex representation of signal analytical signal Frequency information (not so precise) Temporal resolution (not so precise) Filtering and Hilberting of EEG data 3
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 HH cos(ωωtt) = sin(ωωtt) Analytic signal of Mcos ωωtt is: Mcos(ωt) + imsin(ωωtt) Filtering and Hilberting of EEG data 7
Brief recap: Complex numbers http://betterexplained.com/articles/a-visual-intuitive-guide-to-imaginary-numbers/ Filtering and Hilberting of EEG data 8
Simple matlab demo So, how does this look like? Filtering and Hilberting of EEG data 9
Movie illustration Filtering and Hilberting of EEG data 10
Math slide 1: Hilbert transform Definition: p.v. (Cauchy principle value) Some properties: HH HH uu tt = uu(tt) HH uu (tt) = 1 ππ HH 1 = HH uu(ττ) pp. vv. tt ττ ddττ Relation to Fourier transform: F HH uu ωω = ( ii ssssssss(ωω))f uu (ωω) Method used to calculate H in MX Cohen s book. Analytic signal: yy tt = uu tt + iiii[uu](tt) Filtering and Hilberting of EEG data 11
Hilbert Summary 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() Filtering and Hilberting of EEG data 12
Know what you do and what you expect to happen with (artificial) data Matlab s hilbert() works on columns, not rows!!! 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) Filtering and Hilberting of EEG data 13
Hilbert questions The speaker first 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. Filtering and Hilberting of EEG data 14
Hilbert questions The audience Filtering and Hilberting of EEG data 15
Why filtering? Filtering in a nutshell 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 tt 2xx xx ff tt = ττ WW tt + ττ dddd tt 1 Usually the averaging is performed as convolution with a filter kernel K, the so called impulse response function. tt 2xx xx ff tt = ττ KK tt ττ dddd tt 1 Filtering and Hilberting of EEG data 18
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 Convolution with Impulse response function KK tt : xx ff tt = xx ττ KK tt ττ dddd Multiplication with Frequency response function KK ωω : xx ff ωω = xx ωω KK ωω Where ^ denotes the Fourier transform Causal filters KK tt = 0 if tt < 0 Sharp edges in one domain, result in a lot of leak in the other domain!! Filter design Filtering and Hilberting of EEG data 22
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. 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 kernel In this talk, FIR and filter kernel are used interchangeably. Filtering and Hilberting of EEG data 23
Definitions: Frequency pass properties Low pass filter Lets low frequencies pass, attenuates high frequencies High pass filter Lets high frequencies pass, attenuates low frequencies. Band pass filter Lets intermediate frequencies pass, attenuates others. Band stop filter Attenuates intermediate frequencies, lets others pass. Filtering and Hilberting of EEG data 24
Causal filters Definitions: Causality 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. Causal or not? Filtering and Hilberting of EEG data 25
Analog filters Definitions: Analog vs. digital 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! Images: www.wikipedia.org Filtering and Hilberting of EEG data 26
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 Just take the difference between a non-filter (unity) and a low-pass filter. Filtering and Hilberting of EEG data 31
High pass filter Filtering and Hilberting of EEG data 32
Causal vs. non-causal filters Filtering and Hilberting of EEG data 33
Be aware Filters can do stuff to your data (not all of it very intuitive) that can influence your conclusions. E.g. about causality. Filtering and Hilberting of EEG data 34
Designing filters with Matlab(with firls) Filtering and Hilberting of EEG data 35
What is the best filter? Filter design is an art on its own. There is no perfect filter. A chosen filter always has its pros (hopefully) and cons (for sure). Filter design is not the topic today! Filtering and Hilberting of EEG data 36
But let s do some filtering in Matlab Filtering and Hilberting of EEG data 37
But let s do some filtering in Matlab Amplitude of filter Define relevant frequencies Compute IRF and filter data: Filtering and Hilberting of EEG data 38
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 Power at a given frequency does not mean that the brain was oscillating at that frequency. Luck (2014), Chapter 12 Filtering and Hilberting of EEG data 47
Filtering helps seeing oscillations Filtering is like putting on very specific glasses that let through only the red and yellow light and it will always be autumn when you look at a forest! Filtering and Hilberting of EEG data 48
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 Thank you for your attention! Filtering and Hilberting of EEG data 50
The last slide 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. Filtering and Hilberting of EEG data 51