# track3D

Reconstruct a track from pitch, heading and depth data, given a stating position

## Syntax

#### Matlab & Octave

Will come soon!

#### R

track <- track3D(z,phi,psi,sf,r=0.001,q1p=0.02,q2p=0.08,q3p=1.6e-05,tagonx,tagony,enforce=T,x,y)

## Description

This function will use data from a tag to reconstruct a track by fitting a state space model using a Kalman filter. If no x,y observations are provided then this corresponds to a pseudo-track obtained via dead reckoning and extreme care is required in interpreting the results.

## Inputs

Input var | Description | Units | Default |
---|---|---|---|

z | is a vector with depth over time (in meters, an observation) | meters | N/A |

phi | is a vector with pitch over time (in Radians, assumed as a know covariate) | radians | N/A |

psi | is a vector with heading in radians | radians | N/A |

sf | is a scalar defining the sampling rate (in Hz) | Hz | N/A |

r | is the observation error. The default is 0.001 | N/A | 0.001 |

q1p | is the speed state error. The default is 0.02 | N/A | 0.02 |

q2p | is the depth state error. The default is 0.08 | N/A | 0.08 |

q3p | is the x and y state error. The default is 1.6e-05 | N/A | 1.6e-05 |

tagonx | is the Easting of starting position (in meters, so requires projected data) | meters | N/A |

tagony | is the Northing of starting position (in meters, so requires projected data) | meters | N/A |

enforce | is a logical statement. If true, then speed and depth are kept strictly positive | logical | N/A |

x | is the direct observations of Easting (in meters, so requires projected data) | meters | N/A |

y | is the observations of Northing (in meters, so requires projected data) | meters | N/A |

## Outputs

Output var | Description | Units |
---|---|---|

p | is the smoothed speeds | m/s |

fit.ks | is the fitted speeds | m/s |

fit.kd | is the fitted depths | meters |

fit.xs | is the fitted xs | N/A |

fit.ys | is the fitted ys | N/A |

fit.rd | is the smoothed depths | meters |

fit.rx | is the smoothed xs | N/A |

fit.ry | is the smoothed ys | N/A |

fit.kp | is the kalman a posteriori state covariance | N/A |

fit.ksmo | is the kalman smoother variance | N/A |

## Notes & assumptions

- Output sampling rate is the same as the input sampling rate.
- Frame: This function assumes a [north,east,up] navigation frame and a [forward,right,up] local frame. In these frames, a positive pitch angle is an anti-clockwise rotation around the y-axis. A positive roll angle is a clockwise rotation around the x-axis. A descending animal will have a negative pitch angle while an animal rolled with its right side up will have a positive roll angle.
- This function output can be quite sensitive to the inputs used, namely those that define the relative weight given to the existing data, in particular regarding (x,y)=(lat,long); increasing q3p, the (x,y) state variance, will increase the weight given to independent observations of (x,y), say from GPS readings
- The underlying state space model being fitted to the data is described in “Estimating speed using the Kalman filter… and beyond”, equations 5 and 6 a LATTE internal report available from TAM

## Example

### Matlab & Octave

Will come soon!

### R

p <- a2pr(A=beaked_whale$A$data) h <- m2h(M=beaked_whale$M$data,A=beaked_whale$A$data) track=track3D(z=beaked_whale$P$data,phi=p$p,psi=h$h, sf=beaked_whale$A$sampling_rate,r=0.001,q1p=0.02, q2p=0.08,q3p=1.6e-05,tagonx=1000, tagony=1000,enforce=T,x=NA,y=NA) par(mfrow=c(2,1),mar=c(4,4,0.5,0.5)) plot(-beaked_whale$P$data,pch=".",ylab="Depth (m)",xlab="Time") plot(track$fit.rx,track$fit.ry,xlab="X",ylab="Y",pch=".") points(track$fit.rx[c(1,length(track$fit.rx))], track$fit.ry[c(1,length(track$fit.rx))],pch=21,bg=5:6) legend("bottomright",cex=0.7,legend=c("Start","End"),col=c(5,6),pt.bg=c(5,6),pch=c(21,21))

## About

bugs@animaltags.org Last modified: 10 May 2017