Sie sind auf Seite 1von 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

Overview

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.

components. • FT does not have any time resolution. Cohen 2014

Cohen 2014

• FT does not have any time resolution. Cohen 2014 http://nbviewer.ipython.org/github/calebmadrigal/Fourier

http://nbviewer.ipython.org/github/calebmadrigal/Fourier

TalkOSCON/blob/master/images/prism.png

Recap: Fourier Transform (FT)

Recap: Fourier Transform (FT) http://upload.wikimedia.org/wikipedia/commons/7/72/Fourier

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

can think of Fourier transformation at frequency ω as the inner product of the signal with

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?

http://mathinsight.org/media/ima

ge/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].

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].

convolutions with complex oscillatory kernels [Bruns 2003]. http://www.merriam-webster.com/dictionary/convolution Daniel

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

Recap: 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

one signal weighted by another signal that slides along the first signal. repeat Cohen 2014 Daniel

first signal.

repeat

by another signal that slides along the first signal. repeat Cohen 2014 Daniel Renz, Short-time FFT,

Cohen 2014

signal that slides along the first signal. repeat Cohen 2014 Daniel Renz, Short-time FFT, Multi-tapering &

Recap: Convolution

Recap: Convolution http://www.hpleym.no/atcm99/paper8.html Daniel Renz, Short-time FFT, Multi-tapering & Filtering in

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

Recap: Convolution

Recap: Convolution http://www.hpleym.no/atcm99/paper8.html Daniel Renz, Short-time FFT, Multi-tapering & Filtering in

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.

each segment. • Apply Fourier transform to each segment. repeat Cohen 2014 Daniel Renz, Short-time FFT,
each segment. • Apply Fourier transform to each segment. repeat Cohen 2014 Daniel Renz, Short-time FFT,

repeat

• Apply Fourier transform to each segment. repeat Cohen 2014 Daniel Renz, Short-time FFT, Multi-tapering &
Cohen 2014
Cohen 2014

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.

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.

the problem. Idea: smooth signal to zero at the end points. http://www.ni.com/white-paper/4844/en/ Daniel Renz,
the problem. Idea: smooth signal to zero at the end points. http://www.ni.com/white-paper/4844/en/ Daniel Renz,
the problem. Idea: smooth signal to zero at the end points. http://www.ni.com/white-paper/4844/en/ Daniel Renz,

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

to compensate for signal loss (often around 90% overlap). http://www.ni.com/white-paper/4844/en/ Cohen 2014 Daniel

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

around 90% overlap). http://www.ni.com/white-paper/4844/en/ Cohen 2014 Daniel Renz, Short-time FFT, Multi-tapering &

Cohen 2014

Recap: Wavelets

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.

use if frequency-dependent temporal resolution is required.
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.

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.

of an „ideal“ bandpass impulse response for Hilbert. Bruns 2004: Fourier with Hamming window, Hilbert with

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 that window.

referring to the phase of the sinusoid in that window. Cohen 2014 STFT phase in window

Cohen 2014

STFT phase in window

Hilbert / Wavelet phase time series

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.

is equivalent to multiplication in the frequency domain. Slides from J. Heinzle Daniel Renz, Short-time FFT,

Slides from J. Heinzle

Recap: Filtering

Can use filters to cut out a band of frequencies or cut out everything but

a 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.

result in problems in the frequency domain, and vice versa. http://www.ni.com/white-paper/4844/en/ Slides from J.

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

and vice versa. http://www.ni.com/white-paper/4844/en/ Slides from J. Heinzle Daniel Renz, Short-time FFT,

Slides from J. Heinzle

Spectral Leakage

Steep slopes in time domain cause low main-lob width (good!) and high side-lobes (bad!) in the

frequency domain.

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

trade-off between main-lobe width and side-lobe amplitude. http://www.ni.com/white-paper/4844/en/ Daniel Renz,
trade-off between main-lobe width and side-lobe amplitude. http://www.ni.com/white-paper/4844/en/ Daniel Renz,
trade-off between main-lobe width and side-lobe amplitude. http://www.ni.com/white-paper/4844/en/ Daniel Renz,

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.

such as higher- frequency activity or single-trial analysis. Cohen 2014 Daniel Renz, Short-time FFT, Multi-tapering &

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 that has the optimal main lobe energy concentration

(main lobe energy/ total energy).

lobe energy concentration (main lobe energy/ total energy). Daniel Renz, Short-time FFT, Multi-tapering & Filtering

Multitapering

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:

energy concentration > 90%. • Good official tutorial: http://ch.mathworks.com/help/signal/ref/pmtm.html Daniel

http://ch.mathworks.com/help/signal/ref/pmtm.html

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 filters

filters, it‘s more complicated, but higher order filters can quickly get unstable. • Butterworth filter •

can 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.

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

Summary

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.

Filtering of EEG data in SPM12