time series analysis - university of glasgojoachim/tsa/time_series_analysis...fourier transform –...
TRANSCRIPT
![Page 1: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/1.jpg)
Time Series Analysis
Session II
![Page 2: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/2.jpg)
Outline• spectral analysis• FFT• complex numbers• periodogram• power spectrum• windowing• coherence
![Page 3: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/3.jpg)
Spectral Analysis• psd(signal,512,sf,[],256,’mean’)• what are the parameter?
0 5 10 15 20-140
-120
-100
-80
-60
-40
-20
0
20
Frequency
Pow
er S
pect
rum
Mag
nitu
de (d
B)
![Page 4: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/4.jpg)
Fourier transform – the idea• fitting a function with sinusoids• transformation of time series to frequency domain
0 50 100 150 200 250 3000
0.2
0.4
0.6
0.8
1
1.2
1.4
0 50 100 150 200 250 3000
0.2
0.4
0.6
0.8
1
1.2
1.4
2 functions1 functions
![Page 5: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/5.jpg)
Fourier transform – the idea• fitting a function with sinusoids• transformation of time series to frequency domain
0 50 100 150 200 250 3000
0.2
0.4
0.6
0.8
1
1.2
1.4
0 50 100 150 200 250 3000
0.2
0.4
0.6
0.8
1
1.2
1.4
10 functions3 functions
![Page 6: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/6.jpg)
FFT- general remarks• Fast Fourier Transform• optimised algorithm• 2^N number of samples (128,256,512,1024)
![Page 7: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/7.jpg)
FFT in matlab• Example: sunspot data• Y = fft(sunspot);• Y(1)=[]; %just the sum
1700 1750 1800 1850 1900 1950 20000
20
40
60
80
100
120
140
160
180
200Sunspot Data
0 50 100 150 200 250 300-4000
-2000
0
2000
4000
6000
8000
10000
12000
14000FFT
![Page 8: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/8.jpg)
FFT in matlab• symmetric• remove negative frequencies• n=length(Y);• Y=Y(1:floor(n/2));• plot(abs(Y)); %periodogram
0 50 100 150 200 250 300-4000
-3000
-2000
-1000
0
1000
2000
3000
0 5 10 15 20 25 30 35 400
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
2x 10
7
Pow
er
Period (Years/Cycle)
![Page 9: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/9.jpg)
complex numbers
Real
Imaginary
0 10 20 30 40 50 60 70-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
amplitude: length of the arrowphase:
φ
φ
![Page 10: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/10.jpg)
Spectral analysis with FFT• Exercise:
• type “edit fftdemo” and do the steps in the script
![Page 11: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/11.jpg)
Problems with periodogram• Leakage• Accuracy
![Page 12: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/12.jpg)
Leakage
0 1 2 3 4 5 6 7 8 9 100
20
40
60
80
100
120
140
0 50 100 150 200 250 300-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 50 100 150 200 250 300-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
TSFFT
![Page 13: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/13.jpg)
Leakage• occurs for non-periodic signals• non-periodic signals violate FFT assumptions• problem for real-world signals• solution: windowing
![Page 14: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/14.jpg)
Windowing• purpose: make signal periodic (zero at beginning and
end)
0 50 100 150 200 250 300-3
-2
-1
0
1
2
3
4
0 50 100 150 200 250 300-2.5
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
2.5
windowed signal
![Page 15: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/15.jpg)
Windowed sinusoid
0 1 2 3 4 5 6 7 8 9 100
10
20
30
40
50
60
70
0 1 2 3 4 5 6 7 8 9 100
20
40
60
80
100
120
140
FFT of windowed signal
![Page 16: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/16.jpg)
Windowing• windowing does not eliminate leakage but reduces it• actually: it changes the shape of leakage• wintool: to display and analyze windows• standard window is Hanning window• hw=hanning(256);
![Page 17: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/17.jpg)
Accuracy of Periodogram• Question: how does variance of power estimate
decrease with increasing number of samples?• Answer: No at all!• additional information is used to compute power at finer
frequency resolution
![Page 18: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/18.jpg)
Welchs Method
• Welchs Method: – divide time series in segments of equal length (typically 2^N
samples)– apply window– compute fft– average power spectra
![Page 19: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/19.jpg)
Overlap• we loose information!• solution: overlap• typically: half window length
0 50 100 150 200 250 300-2.5
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
2.5
windowed signal
![Page 20: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/20.jpg)
psd function• psd(signal,512,sf,[],256,’mean’)
• [p,f]=psd(signal,512,sf,[],256,’mean’);• p: power spectrum• f: frequency vector
segment
hanning window
overlap
![Page 21: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/21.jpg)
frequency resolution• depends on sampling frequency and length of FFT
segment• sf=256; segment: 256 => 1 Hz resolution• sf=256; segment: 512 => 0.5 Hz resolution
![Page 22: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/22.jpg)
Multitaper• reducing the variance further
• sinusoid (140, 150 Hz) +noise
0 50 100 150 200 250 300 350 400 450 500-55
-50
-45
-40
-35
-30
-25
-20
-15
-10
-5
Frequency (Hz)
Pow
er/fr
eque
ncy
(dB
/Hz)
Thompson Multitaper Power Spectral Density Estimate
0 50 100 150 200 250 300 350 400 450 500-60
-50
-40
-30
-20
-10
0
10
Frequency (Hz)
Pow
er/fr
eque
ncy
(dB
/Hz)
Periodogram Power Spectral Density Estimate
0 50 100 150 200 250 300 350 400 450 500-25
-20
-15
-10
-5
0
5
10
Frequency (Hz)
Pow
er/fr
eque
ncy
(dB
/Hz)
Welch Power Spectral Density Estimate
![Page 23: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/23.jpg)
Exercise• compute power spectrum of EMG with fft only• compute power spectrum with psd function, determine
tremor frequency with given accuracy• change length of FFT segment and type of window and
observe the effect on power spectrum
![Page 24: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/24.jpg)
Coherence – general• Correlation in the frequency domain• normalized between 0-1 (1: complete dependence)• preferred phase difference
![Page 25: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/25.jpg)
Coherence
?
![Page 26: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/26.jpg)
Coherencecohere(signal1,signal2,512,sf,[],256,’mean’)
![Page 27: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/27.jpg)
Confidence interval• analytic (Halliday et al, 1995)• numeric (use random permutation of time series and
compute coherence a large number of times)
![Page 28: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/28.jpg)
Simulation• x=rand(1,10000);• [b,a]=butter(4,2*[10 15]/1000);• xf=filtfilt(b,a,x);• y=xf+0.5*rand(1,10000);• z=xf+0.5*rand(1,10000);• cohere(y,z,1024,1000,[],…
512,'mean')
0 50 100 150 200 250 300 350 400 450 5000
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
Frequency
Coh
eren
ce F
unct
ion
Est
imat
e
![Page 29: Time Series Analysis - University of Glasgojoachim/TSA/Time_Series_Analysis...Fourier transform – the idea • fitting a function with sinusoids • transformation of time series](https://reader031.vdocuments.net/reader031/viewer/2022022005/5ab0a88a7f8b9a284c8b89a4/html5/thumbnails/29.jpg)
Exercise• compute power spectra of EMG and MEG using psd
look for common frequencies• compute coherence between EMG and MEG with
different frequency resolution