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 (p,q can be non-integer)
  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: 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 (p,q can be non-integer)
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(:),method);
0032 
0033 
0034 % tests
0035 if 0
0036     % regular --> regular, different sampling rate
0037     N=45;
0038     t=(0:N)'/N;
0039     x=sin(2*pi*t);
0040     y=nt_resample_interp1(x,10,9,'spline');
0041     figure(1); clf; 
0042     plot(t,x, '.-'); 
0043     hold on
0044     plot(linspace(0,1,size(y,1)),y, '.-'); 
0045 end
0046

Generated on Sat 29-Apr-2023 17:15:46 by m2html © 2005