From 30b428414cb4b1c6df381287ca54b9f0e57c9f0b Mon Sep 17 00:00:00 2001 From: NikAksamit <86243474+NikAksamit@users.noreply.github.com> Date: Fri, 7 Oct 2022 15:11:20 -0700 Subject: [PATCH] Add files via upload --- TSE_Buoy_Example.m | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 TSE_Buoy_Example.m diff --git a/TSE_Buoy_Example.m b/TSE_Buoy_Example.m new file mode 100644 index 0000000..832635e --- /dev/null +++ b/TSE_Buoy_Example.m @@ -0,0 +1,33 @@ +%%%%%%%%%%%%%%% Input Data %%%%%%%%%%%%%%%% +%%% Longitude: vector of lon positions %%%% +%%% Latitude: vector of lat positions %%%%% +%%% time: vector of GPS sampling times %%%% +%%% - units of days %%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +%%%%%%%%%%%%%%% User Variables %%%%%%%%%%%%%%%% +Integration_Time = 3; % Number of days for summing TSE and \bar{TSE} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%% Generate buoy speed times series from lat/lon %%%% +ds=abs(time(2)-time(1)); % Assuming uniform timestep. Units of days. +window = floor(Integration_Time/ds); +Distances=gc_dist_length(Longitdue(1:end-2),Latitude(1:end-2),Longitude_(3:end),Latitude(3:end)); %km +Speed_sqrd=(Distances.^2)/(ds).^2; %km/day + +%%%% Calculate instantaneous TSE measurements %%%% +TSE_Instant=log((Speed_sqrd(2:end))./(Speed_sqrd(1:end-1))); +TSE_Instant(abs(TSE_Instant)==Inf)=NaN; + +%%%% Sum up TSE and \bar{TSE} %%%% +TSE_Bar=1/(time(window+1)-time(1)) * movsum(abs(TSE_Instant),[0 window],'Endpoints','fill'); +TSE=1/(time(window+1)-time(1)) * log((Speed_sqrd(window+1:end))./(Speed_sqrd(1:end-window))); +TSE_Bar(end+1:numel(TSE_Instant))=NaN; +TSE(end+1:numel(TSE_Instant))=NaN; + +%%%% Great circle distance assuming spherical earth %%%% +function [d]=gc_dist_length(long_initial,lat_initial,long_final,lat_final) +r=6371; %km +d=r*2*asin(sqrt(sind((lat_initial-lat_final)/2).^2 + cosd(lat_initial).*cosd(lat_final).*sind((long_initial-long_final)/2).^2) ); +end \ No newline at end of file