resmpl

Capsim Block Documentation

Short Description

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.

Top
Input Connections
Port Type Name
0 float x
Top
Output Connections
Port Type Name
0 float y
Top
Parameters
Num Description Type Name Default Value
0 ratio: output data rate/input data rate. float ratio 1.
1 delay of first output sample, rel. to first sample.Expressed in units of input data period. float phi 0
2 Type of interpolation: 0: sinc (3 point) 1: 1rst order (line) (default) 2: 2nd order (parbola) 3: 3rd order polynomial int intype 1
Top
States
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
Top

Declarations


 

	int i,j;
	float beta;	/* interpolation fraction */
	float beta2;
	float sinc ();	/* custom function in SUBS library */
	int  no_samples;



Top

Initialization Code



 

	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);
	}




Top

Main Code



 

	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;
		}
	}




Top

Wrapup Code



 





Top

License



/*  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
*/


Top

Description



 

/* 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
*/