Laboratory in Oceanography: Data and Methods Additional Topics - Rotary Spectra MAR550, Spring 2013 Miles A. Sundermeyer Sundermeyer MAR 550 Spring 2013 1 Additional Topics Rotary Spectra Rotary Spectra decompose vector time series (e.g., current or wind data) into clockwise and counter-clockwise components. Suppose we have u and v components of velocity: u (t ) A cos(t ) B sin(t ) v(t ) C cos(t ) D sin(t ) These can be written in complex form as: R u iv A cos(t ) B sin(t ) i C cos(t ) D sin(t ) ( A iC ) cos(t ) ( B iD ) sin(t )

Sundermeyer MAR 550 Spring 2013 2 Additional Topics Rotary Spectra Now write R as a sum of clockwise and counter-clockwise rotating components as follows: R R e it R e it R cos(t ) i sin(t ) R cos(t ) i sin(t ) ( R R ) cos(t ) ( R R )i sin(t ) (Note: eit = cos(t) + i sin(t) rotates counter-clockwise in the complex plane, and e-it = cos(t) i sin(t) rotates clockwise.) Comparing this to the final expression on the previous slide, we had: R ( A iC ) cos(t ) ( B iD) sin(t ) Equating the coefficients of the cosine and sine parts, we find: 1 A D i(C B) 2

1 R A D i (C B) 2 R Sundermeyer MAR 550 Spring 2013 3 Additional Topics Rotary Spectra The magnitudes of the rotary components follow as: 1 2 2 R A D C B 2 1 2 2 R A D C B

2 1 1 2 2 Note: since the CW and CCW components are rotating at the same frequency but in opposite directions there will be times when they are additive (pointing in the same direction) and times when they are opposing (pointing in opposite direction) and tend to cancel each other out. These additive and opposing times define the major axis = (R++ R-) and the minor axis = (R+- R-) of an ellipse.

Sundermeyer MAR 550 Spring 2013 4 Additional Topics Rotary Spectra While the orientation and phase of the ellipses: 1 orientation : 2 1 phase : 2 where: Sundermeyer MAR 550

Spring 2013 C B tan 1 AD CB tan 1 A D 5 Additional Topics Rotary Spectra Examples:

Sundermeyer MAR 550 Spring 2013 6 Additional Topics Rotary Spectra Examples: Sundermeyer MAR 550 Spring 2013 7 Additional Topics Rotary Spectra Examples: Sundermeyer MAR 550 Spring 2013 8

Additional Topics Rotary Spectra Examples: Sundermeyer MAR 550 Spring 2013 9 Additional Topics Rotary Spectra Suppose now that we have two time series, ocean current, and wind ... Autospectrum: The autospectrum for each time series is: [ Ac ( f )]2 , f 0 S cc 2 [ A ( f )] , f 0 c S ww

[ Aw ( f )] 2 , f 0 2 [ Aw ( f )] , f 0 e.g., Scc (f 0) is the power spectral density of the counter-clockwise component of the current time-series. The area under this curve versus frequency will equal the variance of the cross-shore and along-shore current velocity components. Sundermeyer MAR 550 Spring 2013 10 Additional Topics Rotary Spectra Inner cross-spectrum: The inner cross-spectrum of two time series compares the joint energy of the two time series for the rotary components rotating in the same direction (e.g. the clockwise component of one vector to the clockwise component of the other vector): S cw ( f ) Wc* ( f )Ww ( f )

Ac ( f ) Aw ( f )e[ i ( c w )] , f 0 [ i ( c w )] Ac ( f ) Aw ( f )e , f 0 with * denoting the complex conjugate and <> representing an ensemble average. Sundermeyer MAR 550 Spring 2013 11 Additional Topics Rotary Spectra Inner coherence squared: The inner coherence-squared between the wind and current time series at frequency (f) is calculated according to:

A A cos( ) 2 A A sin( ) c w c w c w c w Ccw 2 Ac Aw cos( c w ) Ac Aw sin( w w ) 2 2

/ A / A 2 c 2 w A 2 c Aw , f 0 , f 0 2 The coherence ranges from 0 to 1, and represents the similarity (or variability) of the two time series to each other. A value near unity indicates a high degree of correlation, while a coherence near zero indicates a negligible correlation.

Using a 95% confidence interval, a limiting value, or level to which coherencesquared values occur by chance is given by: significant C cw 1 0.5[ 2 /( DOF 2)] where DOF represents the degrees of freedom contained in the time-series. Sundermeyer MAR 550 Spring 2013 12 Additional Topics Rotary Spectra Inner phase: The inner phase for the cross spectrum and coherence measures the phase lead of the rotary component of the one time-series with respect to the other time-series. It can be calculated according to the following equation: A A sin( ) 2 / A A cos( ) 2 , f 0 c w

c w c w c w tan(cw ) 2 2 A A sin( )

/ A A cos( ) , f 0 c w c w c w c w Sundermeyer MAR 550 Spring 2013

13 Additional Topics Rotary Spectra Example: Sundermeyer MAR 550 Spring 2013 14 Additional Topics Rotary Spectra The following are similarly defined for the rotary components rotating in the opposite direction (e.g. the clockwise component of one vector to the anticlockwise component of the other vector) Outer cross-spectrum Outer coherence squared Outer phase Sundermeyer MAR 550 Spring 2013

15 Additional Topics Rotary Spectra Key Points: Rotary spectra decompose complex time series into CW and CCW rotating components. Complex data could be wind, currents, T & S, etc. Can be used to analyze wind, waves or currents and/or to isolate inertial motions, tidal motions, and certain classes of waves. Rotary spectra are invariant under coordinate rotation. References: Mooers, C. N. K., 1973. A technique for the cross spectrum analysis of pairs of complex-valued time series, with emphasis on properties of polarized components and rotational invariants. DSR, 1973, Vol. 20, 1129-1141 Sundermeyer MAR 550 Spring 2013 16 Laboratory in Oceanography: Data and Methods Additional Topics

Other Cool Stuff in Matlab MAR550, Spring 2013 Miles A. Sundermeyer Sundermeyer MAR 550 Spring 2013 17 Additional Topics Other Cool Stuff Functions A function in Matlab is an m-file that allows passing of variables as input and output. Advantage/disadvantage is that the workspace within a function is independent from the workspace calling the function (use global variable declarations, or evalin command to circumvent this) Good for tasks that have to be done frequently, or for complicated tasks to help make code more readable. Sundermeyer MAR 550 Spring 2013

18 Additional Topics Other Cool Stuff Function Syntax Enclose the input argument list in parentheses Separate the inputs with commas Enclose string arguments with single quotation marks Optionally assign any output from the function to one or more output arguments Examples: out = functionname(variable, 'string', expression, ...); [out1, out2, ..., outN] = functionname(in1, in2, ..., inN); Sundermeyer MAR 550 Spring 2013 19 Additional Topics Other Cool Stuff Clearing Functions from Memory You can use clear in any of the following ways to remove functions from the MATLAB workspace. Syntax

Description clear Remove specified function from workspace. clear functions Remove all compiled M-functions. clear all Remove all variables and functions. Any functions called must be within the scope of (i.e., visible to) the calling function or your MATLAB session. The function precedence order determines the precedence of one function over another based on the type of function and its location in MATLABs path Find which function MATLAB calls using the which command, e.g., >> which mean C:\Program Files\MATLAB\R2007a\toolbox\matlab\datafun\mean.m Sundermeyer

MAR 550 Spring 2013 20 Additional Topics Other Cool Stuff Example Suppose we wish to fit a Gaussian curve to data ... Our model is: 2 ( x xo ) y Ae 2 2 where we wish to determine three parameters: A, xo, and To use a linear least squares, we would first need to take logarithm of both sides: ( x x )2 ln y ln Ae

2 ( x xo ) 2 ln A 2 2 o 2 Instead use lsqnonlin, or similar by hand approach to find best fit for three parameters simultaneously Sundermeyer MAR 550 Spring 2013 21 Additional Topics Other Cool Stuff Sundermeyer

MAR 550 Spring 2013 22 Additional Topics Other Cool Stuff Sundermeyer MAR 550 Spring 2013 23 Additional Topics Other Cool Stuff Notable Points Re: Functions: Use nargin to allow variable number of inputs Sometimes useful to pass a function reference to another function, e.g., lsqnonlin Other Miscellaneous Stuff guide - GUI development environment beep.m - beep sound.m

- play sounds Sundermeyer MAR 550 Spring 2013 24