Time series analysis Matlab tutorial. Joachim Gross



Similar documents
Digital filter design for electrophysiological data a practical approach

Em bedded DSP : I ntroduction to Digital Filters

Analog Filters. A common instrumentation filter application is the attenuation of high frequencies to avoid frequency aliasing in the sampled data.

SGN-1158 Introduction to Signal Processing Test. Solutions

SECTION 6 DIGITAL FILTERS

Digital Signal Processing IIR Filter Design via Impulse Invariance

Sampling Theorem Notes. Recall: That a time sampled signal is like taking a snap shot or picture of signal periodically.

chapter Introduction to Digital Signal Processing and Digital Filtering 1.1 Introduction 1.2 Historical Perspective

CHAPTER 6 Frequency Response, Bode Plots, and Resonance

ELEN E4810: Digital Signal Processing Topic 8: Filter Design: IIR

PRACTICAL GUIDE TO DATA SMOOTHING AND FILTERING

Analog and Digital Filters Anthony Garvert November 13, 2015

Lecture 1-6: Noise and Filters

Transition Bandwidth Analysis of Infinite Impulse Response Filters

Frequency Response of Filters

EECS 556 Image Processing W 09. Interpolation. Interpolation techniques B splines

Introduction to Digital Filters

Implementation of the LMS Algorithm for Noise Cancellation on Speech Using the ARM LPC2378 Processor.

Introduction to IQ-demodulation of RF-data

CHAPTER 8 ANALOG FILTERS

SUMMARY. Additional Digital/Software filters are included in Chart and filter the data after it has been sampled and recorded by the PowerLab.

Probability and Random Variables. Generation of random variables (r.v.)

NAPIER University School of Engineering. Electronic Systems Module : SE32102 Analogue Filters Design And Simulation. 4 th order Butterworth response

Design of Efficient Digital Interpolation Filters for Integer Upsampling. Daniel B. Turek

How To Understand The Nyquist Sampling Theorem

Introduction to time series analysis

Frequency response. Chapter Introduction

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

Controller Design in Frequency Domain

FAST Fourier Transform (FFT) and Digital Filtering Using LabVIEW

Experimental validation of loudspeaker equalization inside car cockpits

Lecture 9. Poles, Zeros & Filters (Lathi 4.10) Effects of Poles & Zeros on Frequency Response (1) Effects of Poles & Zeros on Frequency Response (3)

Predictive Indicators for Effective Trading Strategies By John Ehlers

Aliasing, Image Sampling and Reconstruction

Spike-Based Sensing and Processing: What are spikes good for? John G. Harris Electrical and Computer Engineering Dept

Sampling and Interpolation. Yao Wang Polytechnic University, Brooklyn, NY11201

MODULATION Systems (part 1)

ANALYZER BASICS WHAT IS AN FFT SPECTRUM ANALYZER? 2-1

Laboratory #5: RF Filter Design

PYKC Jan Lecture 1 Slide 1

Frequency Response of FIR Filters


Analog signals are those which are naturally occurring. Any analog signal can be converted to a digital signal.

Analog Representations of Sound

2.161 Signal Processing: Continuous and Discrete Fall 2008

Agilent Creating Multi-tone Signals With the N7509A Waveform Generation Toolbox. Application Note

AN-837 APPLICATION NOTE

Lectures 6&7: Image Enhancement

Understanding CIC Compensation Filters

Implementation of Digital Signal Processing: Some Background on GFSK Modulation

TDA W Hi-Fi AUDIO POWER AMPLIFIER

LAB 12: ACTIVE FILTERS

T = 1 f. Phase. Measure of relative position in time within a single period of a signal For a periodic signal f(t), phase is fractional part t p

Voice---is analog in character and moves in the form of waves. 3-important wave-characteristics:

Duobinary Modulation For Optical Systems

Department of Electrical and Computer Engineering Ben-Gurion University of the Negev. LAB 1 - Introduction to USRP

CHAPTER 3: DIGITAL IMAGING IN DIAGNOSTIC RADIOLOGY. 3.1 Basic Concepts of Digital Imaging

Digital Signal Processing Complete Bandpass Filter Design Example

(Refer Slide Time: 01:11-01:27)

Linear Filtering Part II

Sampling: What Nyquist Didn t Say, and What to Do About It

Clutter Filter Design for Ultrasound Color Flow Imaging

1995 Mixed-Signal Products SLAA013

NONLINEAR TIME SERIES ANALYSIS

Time Series Analysis: Introduction to Signal Processing Concepts. Liam Kilmartin Discipline of Electrical & Electronic Engineering, NUI, Galway

Time-series filtering techniques in Stata

LM833,LMF100,MF10. Application Note 779 A Basic Introduction to Filters - Active, Passive,and. Switched Capacitor. Literature Number: SNOA224A

COURSE DESCRIPTOR Signal Processing II Signalbehandling II 7.5 ECTS credit points (7,5 högskolepoäng)

Bandwidth-dependent transformation of noise data from frequency into time domain and vice versa

Impedance 50 (75 connectors via adapters)

UNIVERSITY OF CALIFORNIA, SAN DIEGO Electrical & Computer Engineering Department ECE Fall 2010 Linear Systems Fundamentals

MATRIX TECHNICAL NOTES

Digital image processing

Analog Signal Conditioning

Convolution. 1D Formula: 2D Formula: Example on the web:

Advanced Signal Processing and Digital Noise Reduction

HYBRID FIR-IIR FILTERS By John F. Ehlers

Lab 5 Getting started with analog-digital conversion

Selected Filter Circuits Dr. Lynn Fuller

Matlab GUI for WFB spectral analysis

isim ACTIVE FILTER DESIGNER NEW, VERY CAPABLE, MULTI-STAGE ACTIVE FILTER DESIGN TOOL

A Basic Introduction to Filters Active Passive and Switched-Capacitor

Analysis/resynthesis with the short time Fourier transform

Bildverarbeitung und Mustererkennung Image Processing and Pattern Recognition

PCM Encoding and Decoding:

Evaluating Oscilloscope Sample Rates vs. Sampling Fidelity

Simulation of Frequency Response Masking Approach for FIR Filter design

ELECTRONIC FILTER DESIGN HANDBOOK

RF Network Analyzer Basics

RADIO FREQUENCY INTERFERENCE AND CAPACITY REDUCTION IN DSL

Software for strong-motion data display and processing

Automatic Evaluation Software for Contact Centre Agents voice Handling Performance

Admin stuff. 4 Image Pyramids. Spatial Domain. Projects. Fourier domain 2/26/2008. Fourier as a change of basis

DESIGN AND SIMULATION OF TWO CHANNEL QMF FILTER BANK FOR ALMOST PERFECT RECONSTRUCTION

Filter Comparison. Match #1: Analog vs. Digital Filters

Lecture 14. Point Spread Function (PSF)

Agilent AN 1315 Optimizing RF and Microwave Spectrum Analyzer Dynamic Range. Application Note

INFERRING TRADING STRATEGIES FROM PROBABILITY DISTRIBUTION FUNCTIONS

Sophomore Physics Laboratory (PH005/105)

ECE 3510 Final given: Spring 11

Transcription:

Time series analysis Matlab tutorial Joachim Gross

Outline Terminology Sampling theorem Plotting Baseline correction Detrending Smoothing Filtering Decimation

Remarks Focus on practical aspects, exercises, getting experience (not on equations, theory) Focus on How to do Learn some basic skills for TS analysis Note: Usually there is not a single perfectly correct way of doing a TS operation! => learn the limitations!

What is a time series? A sequence of measurements over time.5.5 -.5-2 4 6 8

Terminology Continuous TS: continuous observations Discrete TS: observations at specific times usually equally spaced Deterministic TS: future values can be exactly predicted from past values Stochastic TS: exact prediction not possible

Objectives of TS analysis Description Explanation Prediction Control

Simple descriptive analysis Summary statistics (mean, std) is not always meaningful for TS 2 8 6 4 2 5 5 2 25 3 35 4 45 5

Sampling Converting a continuous signal into a discrete time series Reconstruction is possible if sampling frequency is greater than twice the signal bandwidth.5.5 -.5 -.5 -.2.4.6.8 Time (s) -.2.4.6.8 75 Hz sampling

Sampling Nyquist frequency: half of sampling frequency 3.5 2 -.5 - -2 -.2.4.6.8-3.2.4.6.8 Hz sampling Hz reconstruction

Sampling Aliasing: Frequencies above Nyquist frequency are reconstructed below Nyquist frequency.5 -.5 -.2.4.6.8 8 Hz sampling

Sampling Aliasing: Frequencies above Nyquist frequency are reconstructed below Nyquist frequency Power Spectrum Magnitude (db) 2-2 -4-6 -8 - -2-4 5 5 2 Frequency 4 Hz sampling Power Spectrum Magnitude (db) 2-2 -4-6 -8 - -2-4 2 3 4 Frequency 8 Hz sampling

Simple operations on TS Plotting Removing a baseline Removing a trend Smoothing Filtering Decimation

Plotting in Matlab For visual inspection of TS For publications/talks plot sptool

Data preprocessing I Removing offset ts=ts-mean(ts); 8.5 6 4 2 -.5.2.4.6.8 -.2.4.6.8

Data preprocessing I Removing a baseline basel=find(t<=); ts=ts-mean(ts(basel)); 5 4 4 3 2 - -2 -.2 -...2.3.4.5.6 3 2 - -2-3 -.2 -...2.3.4.5.6

Data preprocessing II Removing a trend ts=detrend(ts); subtracts best fitting line detrend can be used to subtract mean: detrend(ts, constant ) 5 4 3 2-5 4 3 2 - data linear data 2-2 -.2 -...2.3.4.5.6-2 -3 -.2 -...2.3.4.5.6

Data preprocessing III Smoothing ts=filter(ones(,3)/3,,ts); %mean filter, moving average uses zeros at beginning! => baseline correction or do not use first 3 samples 7 6 5 4 3 2 -.2.2.4.6

Data preprocessing III introduces a shift! => either correct for it or ts=filtfilt(ones(,5)/5,,ts); %mean filter, forward and reverse no shift! filter can take any smoothing kernel (gaussian, etc) 7 shifted by 5 samples 4 filtfilt 6 3 5 2 4 3 2 - -2 -.2.2.4.6-3 -.2.2.4.6

Data preprocessing III Smoothing ts=medfilt(ts,3); %median filter, takes into account the shift uses at beginning and end! 7 4 6 5 4 3 3.5 3 2.5 2 2 -.2 -...2.3.4.5.6.5 -.2 -.8 -.6 -.4 -.2 -.

Data preprocessing III Smoothing ts=sgolayfilt(ts,3,4); %Savitzky-Golay filter fits 3 rd order polynomial to frames of size 4 good at preserving high frequencies in the data 7 6 5 4 3 2 -.2.2.4.6

Data preprocessing III Smoothing compare unsmoothed and smoothed data check for shift check beginning (and end) of the smoothed time series

Exercise

Data preprocessing IV Filtering FIR-Filter (finite impulse response) stable high filter order usually have linear phase (phase change is proportional to frequency) IIR-Filter (infinite impulse response) potentially unstable low filter order non-linear phase distortion computationally efficient

Data preprocessing IV IIR-Filter: Butterworth Elliptic Chebychev Typ Chebychev Typ 2 Bessel FIR-Filter: fir

Data preprocessing IV lowpass highpass bandpass bandstop Magnitude (db) -5 - -5-2 Magnitude Response (db) -25-3 db is logarithmic unit db = factor of 3dB = factor of 2 db= factor of -35-4 5 5 2 25 3 35 4 45 Frequency (Hz) 5 Hz lowpass

Data preprocessing IV lowpass highpass bandpass bandstop Magnitude (db) - -2-3 -4-5 -6 Magnitude Response (db) -7-8 db is logarithmic unit db = factor of 3dB = factor of 2 db= factor of -9-5 5 2 25 3 35 4 45 Frequency (Hz) 3 Hz highpass

Data preprocessing IV lowpass highpass bandpass bandstop Magnitude (db) -5 - -5-2 -25 Magnitude Response (db) -3-35 db is logarithmic unit db = factor of 3dB = factor of 2 db= factor of -4 5 5 2 25 3 35 4 45 Frequency (Hz) 2-3 Hz bandpass

Data preprocessing IV lowpass highpass bandpass bandstop Magnitude (db) -5 - Magnitude Response (db) -5-2 db is logarithmic unit db = factor of 3dB = factor of 2 db= factor of -25 5 5 2 25 3 35 4 45 Frequency (Hz) 3-4 Hz bandstop

Simple design: FIR [b]=fir(4,2*4/sf); %4 Hz lowpass [b]=fir(4,2*4/sf, high ); %4 Hz highpass [b]=fir(4,2*[4 ]/sf); %4- Hz bandpass [b]=fir(4,2*[4 ]/sf, stop ); %4- Hz bandstop tsf=filter(b,,ts); tsf=filtfilt(b,,ts); %forward and reverse

Simple design: IIR [b,a]=butter(4,2*4/sf); %4 Hz lowpass [b,a]=butter(4,2*4/sf, high ); %4 Hz highpass [b,a]=butter(4,2*[4 ]/sf); %4- Hz bandpass [b,a]=butter(4,2*[4 ]/sf, stop ); %4- Hz bandstop tsf=filter(b,a,ts); tsf=filtfilt(b,a,ts); %forward and reverse

Simple Inspection freqz(b,a,,); sf number of frequencies Magnitude (db) - -2 Phase (degrees) -3 5 5 2 25 3 35 4 45 5 Frequency (Hz) - -2-3 -4 5 5 2 25 3 35 4 45 5 Frequency (Hz)

Complex design fdatool magnitude response phase response impulse response compare filters effect of changing filter order

Filter artifacts onset transients filter 2 x Hz lowpass (4th order Butterworth) -3 - -2-3 -4-5 2 x -3 - -2-3 -4-5 filtfilt -6 2 4 6 8-6 2 4 6 8

Filter artifacts ringing 2 x -3 with artifact 2 x -3 without artifact 5 5 5 5-5 3.5 4 4.5-5 3.5 4 4.5

Filter artifacts ringing filter, 2 Hz lowpass (2 th order Butterworth) filtfilt 2 x -3 5 5-5 3.5 4 4.5 x -3 4 3 2 - -2 3.5 4 4.5

Filter artifacts beginning and end of filtered ts is distorted filtering artifacts is dangerous filtering may change the latency of effects! filtering may change the phase

Suggestions be careful with low frequencies use low order butterworth forward and reverse (to avoid phase distortions) carefully check beginning and end of filtered ts make sure you don t have artifacts in the data use surrogate data (filtered noise)

Data preprocessing V Decimation ts=decimate(ts,4); decimate uses a lowpass filter to avoid aliasing artifacts

Exercises 2-4