Date post: | 20-Mar-2018 |
Category: |
Documents |
Upload: | trinhkhuong |
View: | 219 times |
Download: | 3 times |
Time Series Analysis
Session II
Outline• spectral analysis• FFT• complex numbers• periodogram• power spectrum• windowing• coherence
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)
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
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
FFT- general remarks• Fast Fourier Transform• optimised algorithm• 2^N number of samples (128,256,512,1024)
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
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)
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:
φ
φ
Spectral analysis with FFT• Exercise:
• type “edit fftdemo” and do the steps in the script
Problems with periodogram• Leakage• Accuracy
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
Leakage• occurs for non-periodic signals• non-periodic signals violate FFT assumptions• problem for real-world signals• solution: windowing
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
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
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);
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
Welchs Method
• Welchs Method: – divide time series in segments of equal length (typically 2^N
samples)– apply window– compute fft– average power spectra
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
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
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
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
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
Coherence – general• Correlation in the frequency domain• normalized between 0-1 (1: complete dependence)• preferred phase difference
Coherence
?
Coherencecohere(signal1,signal2,512,sf,[],256,’mean’)
Confidence interval• analytic (Halliday et al, 1995)• numeric (use random permutation of time series and
compute coherence a large number of times)
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
Exercise• compute power spectra of EMG and MEG using psd
look for common frequencies• compute coherence between EMG and MEG with
different frequency resolution