21
Sundermeyer MAR 550 Spring 2020 1 Laboratory in Oceanography: Data and Methods MAR550, Spring 2020 Miles A. Sundermeyer Intro to the Signal Processing Toolbox

Laboratory in Oceanography: Data and Methods Intro to the

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 1

Laboratory in Oceanography:

Data and Methods

MAR550, Spring 2020

Miles A. Sundermeyer

Intro to the

Signal Processing Toolbox

Page 2: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 2

Fourier Transform

Suppose we have time or space series data ...

• wish to quantify information content of signal

• wish to separate periodic component from random component

Intro to Signal Processing Toolbox Basics of Fourier Transforms

Page 3: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 3

Intro to Signal Processing Toolbox Frequency Spectra

Variance Preserving Form

• Variance preserving form:

• f · Pxx plotted on a semilogx axis

Page 4: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 4

Fourier Transform (cont’d)

Basic assumptions

• x(t) is one realization from an ensemble of realizations

• x(t) has a mean and correlation function,

• x(t) is stationary

• mean and correlation function are independent of t

(i.e., “weakly” stationary)

• make ergodic assumption – can replace an ensemble average with average

over time of single realization (in general, don’t have multiple realizations)

Intro to Signal Processing Toolbox Basics of Fourier Transforms

N

n

nx txN

t1

)(1

)(

kN

n

xnxnxx tktxtxkN

tkc1

)()(1

)(

Page 5: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 5

Fourier Transform (cont’d)

• Define a finite Fourier transform as:

• Define “Power Spectrum” as:

where * denotes the

complex conjugate

• The power spectrum quantifies the amount of energy contained in different

frequencies in the time series.

• The “theoretical” power spectrum has the property:

Intro to Signal Processing Toolbox Basics of Fourier Transforms

T

fti

kk dtetxTfX0

2)(),(

),(),(1

),,(ˆ * TfXTfXT

kTfS kkxx

deckTfSEfS fi

xxxxTxx

2)(),,(ˆlim)(

where k denotes

realizations within

an ensemble

Page 6: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 6

Fourier Transform (cont’d)

• Problems with this:

• have discrete data (digitized)

• not infinite time series

• only have one realization

In practice, we thus perform Fourier analysis on our single realization:

• By doing this, implicitly assume our finite interval time series is periodic.

Intro to Signal Processing Toolbox Basics of Fourier Transforms

T

fti dtetxfX0

2)()(

0 T

... ...

0 T -T 2T

Page 7: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 7

Fourier Transform (cont’d)

• Matlab uses Fourier transform equivalent to continuous integral transform on

infinite domain:

Intro to Signal Processing Toolbox Basics of Fourier Transforms

dtetxfX fti 2)()(

dfefXtx fti 2)()(

• Discrete transform on finite domain:

N

n

Nnki

nk exX1

/)1)(1(2

N

k

Nnki

kn eXN

x1

/)1)(1(21

Page 8: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 8

Example: simple fft

>> x = 5 + 3*cos(2*pi*[0:7]/8)

>> X = fft(x); % forward fft

>> xnew = ifft(X); % inverse fft

>> [x' fft(x)' xnew']

ans =

8.0000 40.0000 8.0000

5.1213 12.0000 - 0.0000i 7.1213

5.0000 0.0000 + 0.0000i 5.0000

4.8787 0 + 0.0000i 2.8787

2.0000 0 2.0000

0.8787 0 - 0.0000i 2.8787

5.0000 0.0000 - 0.0000i 5.0000

9.1213 12.0000 + 0.0000i 7.1213

Notes:

• Imaginary parts are all zero - no sine component

• First fft value is freq (k-1) = 0, cos(0) = 1, => fft = (npts)*(mean(x)) = 8x5 = 40

• 2nd & 8th fft values are same & real, represent cosine variability with 8 points,

i.e., freq of 2/8. Amp of cosine variability in orig signal = 2*X2/N

• Other terms are zero since zero energy at other freqs.

Intro to Signal Processing Toolbox Basics of Fourier Transforms

Page 9: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 9

Example: simple fft (cont’d) • Add a sine component and repeat >> x = 5 + 3*cos(2*pi*[0:7]/8) -2*sin(4*pi*[0:7]/8) >> X = fft(x); % forward fft >> xnew = ifft(X); % inverse fft >> [x' fft(x)' xnew']

ans =

8.0000 40.0000 8.0000

5.1213 12.0000 - 0.0000i 5.1213

5.0000 0.0000 + 8.0000i 5.0000

4.8787 0 + 0.0000i 4.8787

2.0000 0 2.0000

0.8787 0 - 0.0000i 0.8787

5.0000 0.0000 - 8.0000i 5.0000

9.1213 12.0000 +0.0000i 9.1213

Note: • X3 = 8i, X7 = -8i ... Xn and XN+2-n are complex conjugates • Imag parts of X2 and X7 => sine w/ freq 2*2/N has amp 2*X3/8 = 2. • In General, frequencies represented by fft are: 2*pi(k-1)/N, k = 0:(N/2)

• zero freq (mean), • 2*pi*(1/N) (lowest) ... 2*pi*((N/2 - 1)/N) (highest = Nyquist freq)

Intro to Signal Processing Toolbox Basics of Fourier Transforms

Page 10: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 10

Intro to Signal Processing Toolbox Frequency Spectra

Example: Muddy Creek,

Chatham, MA

• stage data – fft/spectrum

via 4 methods:

• Harmonic analysis

• 1/N X*X

• Matlab’s ‘spectrum’

• Matlab’s ‘periodogram’

Page 11: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 11

Intro to Signal Processing Toolbox Frequency Spectra

Variance Preserving Form

• Variance preserving form:

• f · Pxx plotted on a semilogx axis

Page 12: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 12

Intro to Signal Processing Toolbox Cautions for Fourier Space – Gibbs Phenomenon

Page 13: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 13

Intro to Signal Processing Toolbox Cautions for Fourier Space - Aliasing

Page 14: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 14

Intro to Signal Processing Toolbox Cautions for Fourier Space - Aliasing

signal freq

Nyquist freq

Page 15: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 15

Convolution and filters

• The convolution of two functions is defined as:

where ∗ denotes the convolution operation.

• In Fourier space, the convolution is the product of the Fourier transforms of

the functions:

Intro to Signal Processing Toolbox Signal Processing Toolbox

Page 16: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 16

Intro to Signal Processing Toolbox Signal Processing Toolbox

Convolution and filters (cont’d)

• Matlab’s ‘fdesign’ function for filter building

Page 17: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 17

Intro to Signal Processing Toolbox Signal Processing Toolbox

Example: Low-Pass Filter

Page 18: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 18

Intro to Signal Processing Toolbox Signal Processing Toolbox

Example: Low-Pass Filter (cont’d)

Page 19: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 19

Intro to Signal Processing Toolbox Signal Processing Toolbox

Example: Windowing

Page 20: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 20

Intro to Signal Processing Toolbox Signal Processing Toolbox

Example: Windowing

Page 21: Laboratory in Oceanography: Data and Methods Intro to the

Sundermeyer

MAR 550

Spring 2020 21

Useful Tidbits:

• fft, ifft - compute forward and inverse fft

• pspectrum - for computing various types of spectra

• spectrum.welch - for computing windowed spectra

• butter - for computing Butterworth filters

• freqz - for computing Fourier representations of filters

• filter, filtfilt - for time domain filtering

Some References:

• Bendat, J. S., and A. G. Piersol: Random Data: Analysis and Measurement

Procedures (1st Ed. 1971)

• Priestly, M. B.: Spectral Analysis and Time Series. 1983.

Intro to Signal Processing Toolbox Signal Processing Toolbox