Capsim Block Documentation
This star performs interpolation or decimation on an input data stream, in order to change the output data rate. Polynomial or sinc interpol- ation is used to create output values that occur "between" input points. An initial time offset between the input/output streams can be entered.
Port | Type | Name | |
---|---|---|---|
0 | float | x |
Port | Type | Name | |
---|---|---|---|
0 | float | y |
Num | Type | Name | Initial Value | Description |
---|---|---|---|---|
0 | long | incount | 0 | |
1 | long | outcount | 0 | |
2 | float | phase | phi | |
3 | double | outaccum | phase | |
4 | float | Q | 0 | |
5 | float | R | 0 | |
6 | float | S | 0 |
int i,j; float beta; /* interpolation fraction */ float beta2; float sinc (); /* custom function in SUBS library */ int no_samples; |
---|
if( ratio <= 0) { fprintf(stderr,"resmpl: improper ratio parameter\n"); return(1); } if( intype < 0 || intype > 3) { fprintf(stderr,"resmpl: unknown interpolation type\n"); return(2); } |
---|
for(no_samples=MIN_AVAIL();no_samples >0; --no_samples) { IT_IN(0); incount++; if(intype == 0) ; else if(intype == 1) { Q = x(1) - x(0); R = S = 0; } else if(intype == 2) { Q = -1.5*x(0) + 2*x(1) - .5*x(2); R = .5*x(0) - x(1) + .5*x(2); S = 0; } else if(intype == 3) { Q = -11*x(0)/6 + 3*x(1) - 1.5*x(2) + x(3)/3; R = x(0) - 2.5*x(1) + 2*x(2) - .5*x(3); S = -x(0)/6 + .5*x(1) - .5*x(2) + x(3)/6; } while( (int)outaccum <= incount - 1) { //ST_DBG if(IT_OUT(0)) { KrnOverflow("resmpl",0); return(99); } outcount++; beta = incount- outaccum; if(intype == 0) { y(0) = x(0)*sinc (beta) + x(1)*sinc (1-beta) + x(2)*sinc (2-beta); } else { beta2 = beta*beta; y(0) = x(0) + Q*beta + R*beta2 + S*beta2*beta; } /*this method prevents accumulation of error*/ outaccum = phase + outcount / ratio; } } |
---|
/* Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks) Copyright (C) 1989-2017 Silicon DSP Corporation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA http://www.silicondsp.com Silicon DSP Corporation Las Vegas, Nevada */ |
---|
/* resmpl.s */ /********************************************************************** resmpl() *********************************************************************** This star performs interpolation or decimation on an input data stream, in order to change the output data rate. Polynomial or sinc interpol- ation is used to create output values that occur "between" input points. An initial time offset between the input/output streams can be entered. Param. 1 - (float) ratio: output data rate/input data rate. 2 - (float) phi: delay of first output sample, relative to first input sample; expressed in units of input data period. Normally -1 < phi < 1. default: 0. 3 - (int) intype: type of interpolation: 0: sinc (3 point) 1: 1rst order (line) (default) 2: 2nd order (parbola) 3: 3rd order polynomial Warning: although any output/input rate ratio > 0 will work, some spectral problems can occur. Time interpolation is not optimal, since there is no access to an infinite number of points! This problem is magnified as ratio deviates farther from unity. If ratio < 1 (decimation mode), aliasing can occur if the input signal is not properly bandlimited. Programmer: L.J. Faber Date: June, 1988. Modified by Jie Gao on Oct 25,04 */ |
---|