# fix_pressure

Correct a depth or altitude profile for offsets caused by mis-calibration and temperature.

#### Matlab & Octave

[p,pc] = fix_pressure(p,t,maxp)		% p and t are sensor structures
or
[p,pc] = fix_pressure(p,t,fs,maxp)		% p and t are vectors

#### R

list <- fix_pressure(p, t, maxp = NULL)	        # p and t are sensor structures
or
list <- fix_pressure(p, t, sampling_rate, maxp = NULL)	        # p and t are vectors

Correct a depth or altitude profile for offsets caused by mis-calibration and temperature. This function finds minima in the dive/altitude profile that are consistent with surfacing/landing. It uses the depth/height at these points to fit a temperature regression.

Input var Description Units
p is a sensor structure/list or vector of depth/altitude in meters. meters
t is a sensor structure/list or vector of temperature in degrees Celsius. degrees Celsius
fs/sampling_rate is the sampling rate of p and t in Hz. This is only needed if p and t are not sensor strucures/lists. The depth and temperature must both have the same sampling rate (use decdc.m or resample.m if needed to achieve this).Hz
maxp is the maximum depth or altitude reading in the pressure data for which the animal could actually be at the surface. This is a rough measurement of the potential error in the pressure data. The unit is meters. Start with a small value, e.g., 2 m and re-run fix_depth with a larger value if there are still obvious temperature-related errors in the resulting depth/altitude profile.meters
Output var Description Units
p is a sensor structure/list or vector of corrected depth/altitude measurements at the same sampling rate as the input data. If the input is a sensor structure/list, the output will also be. meters
pc is a structure/list containing the pressure offset and temperature correction coefficients. It has fields: pc.tref is the temperature reference in degrees Celsius (this will always be 20. pc.tcomp is the temperature compensation polynomial. This is used within the function to correct pressure as follows: p = p+polyval(pc.tcomp,t-pc.tref) N/A
1. This function makes a number of assumptions about the depth/altitude data and about the behaviour of animals:
1. the depth data should have few incorrect outlier (negative) values that fall well beyond the surface. These can be reduced using median_filter.m before calling fix_depth.
2. the animal is assumed to be near the surface at least 2% of the time. If the animal is less frequently at the surface, you may need to change the value of PRCTSURF near the start of the function.
3. potential surfacings are detected by looking for zero-crossings in the vertical speed and this requires defining a threshold in vertical speed that must be crossed by each zero crossing. The value used is 0.05 m/s but this may be too high for animals that move very slowly near the surface. In which case, change MAXSPEED near the start of the function.

### Matlab & Octave

Example coming soon!

### R

Example coming soon!