Home > NoiseTools > nt_resample_interp1.m

# nt_resample_interp1

## PURPOSE

y=resample_interp1(x,p,q,method) - Resample using interp1 (no antialiasing)

## SYNOPSIS

function y=nt_resample_interp1(x,p,q,method)

## DESCRIPTION

    y=resample_interp1(x,p,q,method) - Resample using interp1 (no antialiasing)

      y: resampled signal

      x: data to resample
      p,q: resample to p/q original sampling rate (can be fractional)
      method: interpolation method [default: 'spline']

     From interp1:
           'linear'   - linear interpolation
           'nearest'  - nearest neighbor interpolation
           'next'     - next neighbor interpolation
           'previous' - previous neighbor interpolation
           'spline'   - piecewise cubic spline interpolation (SPLINE)
           'pchip'    - shape-preserving piecewise cubic interpolation
           'cubic'    - same as 'pchip'
           'v5cubic'  - the cubic interpolation from MATLAB 5, which does not
                        extrapolate and uses 'spline' if X is not equally
                        spaced.
           'makima'   - modified Akima cubic interpolation

     NoiseTools

## CROSS-REFERENCE INFORMATION

This function calls:

- nt_greetings nt_greetings - display message the first time the toolbox is used

This function is called by:

## SOURCE CODE

    0001 function  y=nt_resample_interp1(x,p,q,method)
    0002 %y=resample_interp1(x,p,q,method) - Resample using interp1 (no antialiasing)
    0003 %
    0004 %  y: resampled signal
    0005 %
    0006 %  x: data to resample
    0007 %  p,q: resample to p/q original sampling rate (can be fractional)
    0008 %  method: interpolation method [default: 'spline']
    0009 %
    0010 % From interp1:
    0011 %       'linear'   - linear interpolation
    0012 %       'nearest'  - nearest neighbor interpolation
    0013 %       'next'     - next neighbor interpolation
    0014 %       'previous' - previous neighbor interpolation
    0015 %       'spline'   - piecewise cubic spline interpolation (SPLINE)
    0016 %       'pchip'    - shape-preserving piecewise cubic interpolation
    0017 %       'cubic'    - same as 'pchip'
    0018 %       'v5cubic'  - the cubic interpolation from MATLAB 5, which does not
    0019 %                    extrapolate and uses 'spline' if X is not equally
    0020 %                    spaced.
    0021 %       'makima'   - modified Akima cubic interpolation
    0022 %
    0023 % NoiseTools
    0024 nt_greetings;
    0025
    0026 if nargin < 4|| isempty(method); method='spline';   end
    0027 if nargin<3; error('!'); end
    0028
    0029 nsamples=size(x,1);
    0030 querypoints=1+(0:q/p:nsamples-1);
    0031 y=interp1((1:nsamples)',x,querypoints(:));
    0032
    0033