short-time fft, multi-taper analysis & filtering in spm12 · short-time fft, multi-taper...

27
Short-time FFT, Multi-taper analysis & Filtering in SPM12 Computational Psychiatry Seminar, FS 2015 Daniel Renz, Translational Neuromodeling Unit, ETHZ & UZH 20.03.2015

Upload: dinhlien

Post on 03-May-2018

233 views

Category:

Documents


4 download

TRANSCRIPT

Short-time FFT, Multi-taper analysis & Filtering in SPM12

Computational Psychiatry Seminar, FS 2015Daniel Renz, Translational Neuromodeling Unit, ETHZ & UZH

20.03.2015

Overview

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 2

• Refresher

• Short-time Fourier transform

• Filter design

• Multitapering

• Filtering of EEG data in SPM12

Recap: Fourier Transform (FT)

• Our goal: To analyze event related signal changes in the time-frequency domain.

• FT expands a function in terms of sinusoids (or complex exponentials) to fully reveal all frequency components.

• FT does not have any time resolution.

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 3

http://nbviewer.ipython.org/github/calebmadrigal/FourierTalkOSCON/blob/master/images/prism.png

Cohen 2014

Recap: Fourier Transform (FT)

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 4

http://upload.wikimedia.org/wikipedia/commons/7/72/Fourier_transform_time_and_frequency_domains_%28small%29.gif

Recap: Inner product (dot product)

• Measures covariance / similarity / non-orthogonality between two vectors(the inner product of orthogonal vectors is zero).

• Can be extended to functions.

• Any two sinusoids of different frequency are orthogonal. This means that sinusoids can be used as basis functions.

• We can think of Fourier transformation at frequency ω as the inner product of the signal with a complex-valued oscillation.

• As the basis functions are orthogonal, the Fourier-transform gives a perfect representation of the frequency spectrum.

• How to extend this to have temporal resolution?

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 5

http://mathinsight.org/media/image/image/dot_product_projection_unit_vector.png

How to get a time-frequency representation

• Model-free non-parametric methods: Short-time Fourier, Wavelet, Hilbert.

• We can view all three methods as convolutions with complex oscillatory kernels [Bruns 2003].

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 6

How to get a time-frequency representation

• Model-free non-parametric methods: Short-time Fourier, Wavelet, Hilbert.

• We can view all three methods as convolutions with complex oscillatory kernels [Bruns 2003].

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 7

http://www.merriam-webster.com/dictionary/convolution

• We can think of convolution as the extension of the inner product (dot product) to incorporate timelags.

• Compute the inner product of signal with kernel (window) at beginning of signal, then move across the signal, computing products on the way.

• Outcome: time series of one signal weighted by another signal that slides along the first signal.

Recap: Convolution

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 8

repeat

Cohen 2014

Recap: Convolution

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 9

http://www.hpleym.no/atcm99/paper8.html

Recap: Convolution

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 10

http://www.hpleym.no/atcm99/paper8.html

Short-time Fourier Transform (STFT)

• Segment signal in narrow time segments.

• Taper (apply window on segment) each segment.

• Apply Fourier transform to each segment.

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 11

Cohen 2014

repeat

Short-time Fourier Transform (STFT)

• What shape should the window function have? Boxcar, Gaussian, ...

• How wide should it be?

• Should be narrow enough to consider windowed signal stationary.

• Narrow windows do not offer good localization in the frequency domain.

• Uncertainty principle: There is always a trade-off.

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 12

Windows in STFT

• Should not use boxcar function as a window, as this will lead to unwanted artifacts.

• The discontinuities at the ends of the signal are the problem. Idea: smooth signal to zero at the end points.

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 13

http://www.ni.com/white-paper/4844/en/

Windows in STFT

• Should not use boxcar function as a window, as this will lead to unwanted artifacts.

• Many possible windows, e.g. Hann, Hamming, Gaussian.

• A Gaussian has the same localization in time and frequency domain.

• Often Hann is preferred, because it tapers the data fully to zero.

• Use overlapping segments to compensate for signal loss (often around 90% overlap).

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 14

Cohen 2014

http://www.ni.com/white-paper/4844/en/

Recap: Wavelets

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 15

• Complex Morlet wavelet: Complex-valued oscillation multiplied by Gaussian-shaped envelope.

• Variance of Gaussian envelope scales with frequency of oscillation.

• The wavelet is convolved with the signal of interest. This effectively implements a band-pass filter.

• No fundamental difference to STFT with Gaussian window, but more convenient to use if frequency-dependent temporal resolution is required.

http://upload.wikimedia.org/wikipedia/commons/c/c4/STFT_and_WT.jpg

Recap: Hilbert analysis

• Window on frequencies only (via band-pass filter).

• Then extend the signal to the complex plane (analytic signal) via Hilbert transform.

• One can show that this, too, is equivalent to convolution of the signal with a complex oscillatory kernel [Bruns 2003].

• In practice, Hilbert analysis allows for direct control over filter properties as compared to wavelets.But it‘s also more complicated.

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 16

Comparing STFT, Wavelet and Hilbert

• Formally, they are very close (convolutions with complex-valued kernels).

• Practical differences:

• Computation speed, ease-of-use

• Conventional shape of kernel: Gaussian for Wavelets, Hamming for STFT, the equivalent of an „ideal“ bandpass impulse response for Hilbert.

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 17

Bruns 2004: Fourier with Hamming window, Hilbert with ideal bandpass filter (smooth flanks) and complex Morlet wavelet.

Comparing STFT, Wavelet and Hilbert

• The interpretation of power is the same for STFT, filter-Hilbert and wavelet convolution.

• The interpretation of phase changes

• Hilbert / Wavelet methods give instantaneous phase (phase at each time point).

• STFT gives one phase value per time window, referring to the phase of the sinusoid in thatwindow.

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 18

STFT phase in window Hilbert / Wavelet phase time series

Cohen 2014

Recap: Filtering

• We can think of filtering as a clever kind of averaging performed as a convolution with a filter‘s impulse reponse function (Thus, STFT can also be viewed as a filtering procedure).

• And this is equivalent to multiplication in the frequency domain.

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 19

Slides from J. Heinzle

Recap: Filtering

• Can use filters to cut out a band offrequencies or cut out everything buta band of frequencies.

• But not perfectly: Precise cutoffs in the time domain (box-car function!) result in problems in the frequency domain, and vice versa.

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 20

Slides from J. Heinzle

http://www.ni.com/white-paper/4844/en/

Spectral Leakage

• Steep slopes in time domain cause low main-lobwidth (good!) and high side-lobes (bad!) in the frequency domain.

• Fundamental trade-off between main-lobe width and side-lobe amplitude.

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 21

http://www.ni.com/white-paper/4844/en/

Multitapering

• Idea: Apply several tapers (window functions) that have slightly different temporal characteristics and then average the power spectra.

• This increases the SNR, so it’s useful for situations of low SNR ratio, such as higher-frequency activity or single-trial analysis.

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 22

Cohen 2014

Multitapering: Slepian tapers

• If we use orthogonal tapers, windowed signals provide independent spectral estimates.

• This reduces estimation bias of power.

• Discrete prolate spheroidal sequence (DPSS, also known as Slepian sequence) is the orthogonal sequence thathas the optimal main lobe energy concentration(main lobe energy/ total energy).

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 23

• More tapers means more smoothing.

• How much smoothing is appropriate? Trade-Off between SNR and accuracy.

• In MATLAB, the function dpss will compute a number of tapers, based on the desired spectral smoothing and the length of the time segment.

• [desired segment length] * [frequency bandwidth of main lobe] = 2* [number of tapers].

• Should only use tapers with energy concentration > 90%.

• Good official tutorial: http://ch.mathworks.com/help/signal/ref/pmtm.html

Multitapering

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 24

Filter design

• Can optimize two out of three requirements: filter order (lower=better), main lobe width (narrower=better) and side-lobe amplitude (lower=better).

• Filter order refers to the complexity of the filter.

• In FIR filters, it specifies the number of time points in the signal that are used to compute the filter output (so higher order = more temporal smoothing).

• In IIR filters, it‘s more complicated, but higher order filterscan quickly get unstable.

• Butterworth filter

• IIR filter that is maximally flat in the pass-band (no ripples).

• This means that the transition band is really wide.

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 25

http://www.electronics-tutorials.ws/filter/fil57.gif

• By Multitapering we mean taking the average of several STFT on the same signal with orthogonal windows. This improves SNR at the cost of more smoothing.

• STFT, Wavelet and Hilbert can all be thought of as convolving the signal with complex oscillatory kernels.

• Which one you want to use depends on your requirements

• STFT by default has a fixed resolution across frequencies and enables multitapering

• Wavelets provide higher temporal resolutions for higher frequencies.

• Hilbert is flexible, as it gives complete control over filter design.

• Designing a good filter is difficult and always depends on your specific goals. The butterworth filter is a good general-purpose choice, as it has a flat pass-band.

Summary

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 26

Filtering of EEG data in SPM12

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 27