applySeabirdPressureFilter

PURPOSE ^

APPLYPRESSUREFILTER Pressure filtering with regular resampling for Seabird sensor.

SYNOPSIS ^

function new_pressure = applySeabirdPressureFilter(time, old_pressure, time_constant)

DESCRIPTION ^

APPLYPRESSUREFILTER  Pressure filtering with regular resampling for Seabird sensor.

  Syntax:
    NEW_PRESSURE = APPLYSEABIRDPRESSUREFILTER(TIME, OLD_PRESSURE, TIME_CONSTANT)
    NEW_PRESSURE = APPLYSEABIRDPRESSUREFILTER(TIME, OLD_PRESSURE)

  Description:
    NEW_PRESSURE = APPLYSEABIRDPRESSUREFILTER(TIME, OLD_PRESSURE, TIME_CONSTANT)
    applies a low pass filter to the pressure time serie in vector OLD_PRESSURE
    with irregular timestamps in vector TIME. The filter applied is the one in
    function SEABIRDFILTER with duration parameter given by the scalar
    TIME_CONSTANT. The filtered pressure is returned in vector NEW_PRESSURE.

    NEW_PRESSURE = APPLYSEABIRDPRESSUREFILTER(TIME, OLD_PRESSURE) applies 
    the low pass filter with default duration parameter of 4 time units.

    The filtering is performed as follows:
      - Invalid values (NaN) in input are ignored, but preserved in the result.
      - The signal is resampled at regular intervals of unit time length.
        Hence, if TIME is given in seconds, the filter is applied to a new
        sequence with sampling rate 1 Hz.
      - The filter in function SEABIRDFILTER is applied to the resampled signal
        with duration parameter TIME_CONSTANT.
      - The resulting filtered signal is resampled at the original time
        instants.
 
  Notes:
    This function is a version of the function APPLYPRESSUREFILTER created by
    Tomeu Garau. He is the true glider man. Main changes are:
      - Time constant argument.
      - Duplicate record handling removal.
      - Coding style adaptions.

  Examples:
    % Use default time constant parameter (4 seconds).
    new_pressure = applySeabirdPressureFilter(time, old_pressure)
    % Use custom time constant parameter.
    new_pressure = applySeabirdPressureFilter(time, old_pressure, 6)
 
  See also:
    SEABIRDFILTER
    INTERP1

  Authors:
    Bartolome Garau  tgarau@socib.es

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

applySeabirdPressureFilter.m

SOURCE CODE ^

0001 function new_pressure = applySeabirdPressureFilter(time, old_pressure, time_constant)
0002 %APPLYPRESSUREFILTER  Pressure filtering with regular resampling for Seabird sensor.
0003 %
0004 %  Syntax:
0005 %    NEW_PRESSURE = APPLYSEABIRDPRESSUREFILTER(TIME, OLD_PRESSURE, TIME_CONSTANT)
0006 %    NEW_PRESSURE = APPLYSEABIRDPRESSUREFILTER(TIME, OLD_PRESSURE)
0007 %
0008 %  Description:
0009 %    NEW_PRESSURE = APPLYSEABIRDPRESSUREFILTER(TIME, OLD_PRESSURE, TIME_CONSTANT)
0010 %    applies a low pass filter to the pressure time serie in vector OLD_PRESSURE
0011 %    with irregular timestamps in vector TIME. The filter applied is the one in
0012 %    function SEABIRDFILTER with duration parameter given by the scalar
0013 %    TIME_CONSTANT. The filtered pressure is returned in vector NEW_PRESSURE.
0014 %
0015 %    NEW_PRESSURE = APPLYSEABIRDPRESSUREFILTER(TIME, OLD_PRESSURE) applies
0016 %    the low pass filter with default duration parameter of 4 time units.
0017 %
0018 %    The filtering is performed as follows:
0019 %      - Invalid values (NaN) in input are ignored, but preserved in the result.
0020 %      - The signal is resampled at regular intervals of unit time length.
0021 %        Hence, if TIME is given in seconds, the filter is applied to a new
0022 %        sequence with sampling rate 1 Hz.
0023 %      - The filter in function SEABIRDFILTER is applied to the resampled signal
0024 %        with duration parameter TIME_CONSTANT.
0025 %      - The resulting filtered signal is resampled at the original time
0026 %        instants.
0027 %
0028 %  Notes:
0029 %    This function is a version of the function APPLYPRESSUREFILTER created by
0030 %    Tomeu Garau. He is the true glider man. Main changes are:
0031 %      - Time constant argument.
0032 %      - Duplicate record handling removal.
0033 %      - Coding style adaptions.
0034 %
0035 %  Examples:
0036 %    % Use default time constant parameter (4 seconds).
0037 %    new_pressure = applySeabirdPressureFilter(time, old_pressure)
0038 %    % Use custom time constant parameter.
0039 %    new_pressure = applySeabirdPressureFilter(time, old_pressure, 6)
0040 %
0041 %  See also:
0042 %    SEABIRDFILTER
0043 %    INTERP1
0044 %
0045 %  Authors:
0046 %    Bartolome Garau  tgarau@socib.es
0047 
0048 %  Copyright (C) 2013-2016
0049 %  ICTS SOCIB - Servei d'observacio i prediccio costaner de les Illes Balears
0050 %  <http://www.socib.es>
0051 %
0052 %  This program is free software: you can redistribute it and/or modify
0053 %  it under the terms of the GNU General Public License as published by
0054 %  the Free Software Foundation, either version 3 of the License, or
0055 %  (at your option) any later version.
0056 %
0057 %  This program is distributed in the hope that it will be useful,
0058 %  but WITHOUT ANY WARRANTY; without even the implied warranty of
0059 %  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0060 %  GNU General Public License for more details.
0061 %
0062 %  You should have received a copy of the GNU General Public License
0063 %  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0064 
0065   error(nargchk(2, 3, nargin, 'struct'));
0066   
0067   % Check if time constant specified.
0068   if nargin < 3
0069     time_constant = 4;
0070   end
0071 
0072   % Initialize output.
0073   new_pressure = nan(size(old_pressure));
0074   
0075   % Filter invalid values in original data.
0076   % The positive time test is needed to deal with odd data from initial
0077   % lines in Slocum segment files.
0078   good_rows = ~isnan(old_pressure) & (time > 0);
0079   old_pres_signal = old_pressure(good_rows);
0080   time_range  = time(good_rows);
0081 
0082   % Interpolation routine interp1 requires all nodes to have unique independent
0083   % variable coordinates. This might not be the case when the CTD timestamp is
0084   % used. So check for uniqueness and data coherency.
0085   [time_range_unique, index_from, index_to] = unique(time_range);
0086   old_pres_unique = old_pres_signal(index_from);
0087   if any(old_pres_signal ~= old_pres_unique(index_to))
0088     error('glider_toolbox:applySeabirdFilter:InconsistentData', ...
0089           'Inconsistent pressure data.');
0090   end
0091   
0092   % Set the pressure time series on a regular time basis of unit length.
0093   reg_time_range = min(time_range_unique):max(time_range_unique);
0094   reg_pres_signal = interp1(time_range_unique, old_pres_unique, reg_time_range);
0095   
0096   % Filter the regular time series.
0097   new_pres_signal = seabirdFilter(reg_pres_signal, time_constant, 1);
0098   
0099   % Set the time series on its original time instants.
0100   new_pres_signal = interp1(reg_time_range, new_pres_signal, time_range);
0101 
0102   % Return the filtered signal preserving original invalid values.
0103   new_pressure(good_rows)  = new_pres_signal;
0104 
0105 end

Generated on Fri 06-Oct-2017 10:47:42 by m2html © 2005