⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filtestc.c

📁 arm ads1.2 with crack.rar
💻 C
📖 第 1 页 / 共 2 页
字号:
}

/**** PerformIIR ********************************************************************
 *
 * Version & Date
 * -------   ----
 * 1.0.0, 30/06/1998
 *
 * Description
 * -----------
 * given an array of data values and an array of coefficients, IIR filter the data using
 * either ARM or C routines and return the filtered values
 *
 * Inputs
 * ------
 *   inputs
 *   - an array referencing the data inputs
 *   nInputs
 *   - the number of data points referenced by the array inputs
 *   coeffs
 *   - an array referencing the coefficients to be used during the filter
 *   nCoeffs
 *   - the number of coefficients referenced by the array coeffs
 *   arm
 *   - 1 : use ARM Assembler routines to perform the filter
 *     0 : use C routines to perform the filter
 * Return Values
 * ------ ------
 *     int * - an array of filtered values with nInputs data points
 *     NULL  - some error occurred (memory allocation failed?)
 *
 * Memory allocated (not deallocated)
 * ------ ---------  --- -----
 * the returned array of integers
 * deallocate after use
 *
 * History (with dates)
 * -------  ---- -----
 * 1.0.0, 30/06/1998    first release
 *
 ************************************************************************************/
static int *PerformIIR( int inputs[ ], unsigned int nInputs, int coeffs[ ], unsigned int nCoeffs, Boolean arm )
{
	int	*outputs ;

	if( ( outputs = ( int * )calloc( nInputs, sizeof( int ) ) ) == NULL ) {
		fprintf( stderr, "Failure to create array for output data, aborting.\n\n" ) ;
		return NULL ;
	}
	
	if( arm ) {
		printf( "ARM " ) ;
	}
	else {
		printf( "C " ) ;
	}
	printf( "IIR filtering data...\n\n" ) ;
	
	if( arm ) {
		if( !( PerformIIRARM( outputs, inputs, nInputs, coeffs, nCoeffs ) ) ) {
			free( ( void * ) outputs ) ;
			return NULL ;
		}
	}
	else {
		IIRC( outputs, inputs, nInputs, coeffs, nCoeffs ) ;
	}
	
	printf( "Data IIR filtered.\n\n" ) ;
	
	return outputs ;
}

/**** PerformIIRARM *****************************************************************
 *
 * Version & Date
 * -------   ----
 * 1.0.0, 30/06/1998
 *
 * Description
 * -----------
 * given an array of data values and an array of coefficients, IIR filter the data using
 * ARM routines and return the filtered values in the array given
 *
 * Inputs
 * ------
 *   outputs
 *   - an initialised array that references at least nInputs locations
 *   inputs
 *   - an array referencing the data inputs
 *   nInputs
 *   - the number of data points referenced by the array inputs
 *   coeffs
 *   - an array referencing the coefficients to be used during the filter
 *   nCoeffs
 *   - the number of coefficients referenced by the array coeffs
 * Outputs
 * -------
 *   outputs
 *   - the result of the filtering, with nInputs filtered data points
 *     undefined if FALSE returned (see Return Values)
 * Return Values
 * ------ ------
 *     TRUE  - the array outputs contains the filtered data
 *     FALSE - some error occurred (memory allocation?) and outputs is undefined
 *
 * History (with dates)
 * -------  ---- -----
 * 1.0.0, 30/06/1998    first release
 *
 ************************************************************************************/
static Boolean PerformIIRARM( int outputs[ ], int inputs[ ], unsigned int nInputs, int coeffs[ ], unsigned int nCoeffs )
{
	unsigned int	nBiquads = nCoeffs / 4 ;
	int				*coeffsStates ;
	
	if( ( coeffsStates = ( int * )calloc( ( nCoeffs*3 )/2, sizeof( int ) ) ) == NULL ) {
		fprintf( stderr, "Failure to create array for coefficients and states, aborting.\n\n" ) ;
		return FALSE ;
	}

	
	IIR_PowerUp( coeffsStates, coeffs, nBiquads ) ;
	IIR( outputs, inputs, nInputs, nBiquads, coeffsStates ) ;
	
	free( ( void * ) coeffsStates ) ;
	
	return TRUE ;
}

/**** PerformLMS ********************************************************************
 *
 * Version & Date
 * -------   ----
 * 1.0.0, 30/06/1998
 *
 * Description
 * -----------
 * given an array of data values and an array of coefficients, read in a set of desired
 * values from a file given by the user, get an adaption rate, LMS filter the data using
 * either ARM or C routines and return the filtered values
 *
 * Inputs
 * ------
 *   inputs
 *   - an array referencing the data inputs
 *   nInputs
 *   - the number of data points referenced by the array inputs
 *   coeffs
 *   - an array referencing the coefficients to be used during the filter
 *   nCoeffs
 *   - the number of coefficients referenced by the array coeffs
 *   arm
 *   - 1 : use ARM Assembler routines to perform the filter
 *     0 : use C routines to perform the filter
 * Return Values
 * ------ ------
 *     int * - an array of filtered values with nInputs data points
 *     NULL  - some error occurred (memory allocation failed?)
 *
 * Memory allocated (not deallocated)
 * ------ ---------  --- -----
 * the returned array of integers
 * deallocate after use
 *
 * History (with dates)
 * -------  ---- -----
 * 1.0.0, 30/06/1998    first release
 *
 ************************************************************************************/
static int *PerformLMS( int inputs[ ], unsigned int nInputs, int coeffs[ ], unsigned int nCoeffs, Boolean arm )
{
	int 			*desired ;
	unsigned int	nDes ;
	double			adaptRate ;
	int				*outputs ;
	
	if( ( desired = ( int * )GetData( WORDBYTES, "desired", &nDes ) ) == NULL ) {
		return NULL ;
	}
	SIGNEXTENDARRAY( desired, nDes, 16 ) ;
	
	if( nDes != nInputs ) {
		fprintf( stderr, "The number of desired inputs != number of data inputs, aborting.\n\n" ) ;
		free( ( void * ) desired ) ;
		return NULL ;
	}
	
    printf( "Please choose an adaption rate for the filter.\n\n" ) ;
    
    printf( "The larger the adapation rate, the faster the filter will respond,\n" ) ;
    printf( "but the more likely it will also become unstable.\n\n" ) ;
    
    do {
    	printf( "Give an adaption rate, ar, such that 0 < ar < 1: " ) ;
    } while( ( ( adaptRate = ReadDouble( ) ) <= 0.0 ) || ( adaptRate >= 1.0 ) ) ;

    printf( "The adaption rate given is '%lf'\n\n", adaptRate ) ;
    
    /* fix-point the adaption rate */
    adaptRate = adaptRate * ( 1 << 14 ) ;
    
   	if( ( outputs = ( int * )calloc( nInputs, sizeof( int ) ) ) == NULL ) {
		fprintf( stderr, "Failure to create array for output data, aborting.\n\n" ) ;
		free( ( void * ) desired ) ;
		return NULL ;
	}

	if( arm ) {
		printf( "ARM " ) ;
	}
	else {
		printf( "C " ) ;
	}
	printf( "LMS filtering data...\n\n" ) ;

    if( arm ) {
    	if( !( PerformLMSARM( outputs, inputs, nInputs, coeffs, nCoeffs, desired, ( unsigned int )adaptRate ) ) ) {
    		free( ( void * ) desired ) ;
    		free( ( void * ) outputs ) ;
    		return NULL ;
    	}
    }
    else {
    	LMSC( outputs, inputs, nInputs, coeffs, nCoeffs, desired, ( unsigned int )adaptRate ) ;
    }
    
	printf( "Data LMS filtered.\n\n" ) ;
	
	free( ( void * ) desired ) ;
	
	return outputs ;
}

/**** PerformLMSARM *****************************************************************
 *
 * Version & Date
 * -------   ----
 * 1.0.0, 30/06/1998
 *
 * Description
 * -----------
 * given an array of data values, an array of coefficients, an array of desired values
 * and an adaption rate, LMS filter the data using ARM routines and return the 
 * filtered values in the array given and update the coefficient array with the
 * modified values
 *
 * Inputs
 * ------
 *   outputs
 *   - an initialised array that references at least nInputs locations
 *   inputs
 *   - an array referencing the data inputs
 *   nInputs
 *   - the number of data points referenced by the array inputs
 *   coeffs
 *   - an array referencing the coefficients to be used during the filter
 *   nCoeffs
 *   - the number of coefficients referenced by the array coeffs
 *   desired
 *   - an array referencing at least nInputs values that represent the desired outputs
 *     that the filter is based on
 *   adaptRate
 *   - the adaption rate for the filter between 0 and 1 that governs the speed of
 *     learning
 *     actual value is 14-bit fixed point extended to allow for floating point rate
 * Outputs
 * -------
 *   outputs
 *   - the result of the filtering, with nInputs filtered data points
 *     undefined if FALSE returned (see Return Values)
 *   coeffs
 *   - the updated coefficient values after the filtering has adapted them
 *     the original coefficinet values if FALSE returned (see Return Values)
 * Return Values
 * ------ ------
 *     TRUE  - the array outputs contains the filtered data, coeffs updated
 *     FALSE - some error occurred (memory allocation?) and outputs is undefined
 *
 * History (with dates)
 * -------  ---- -----
 * 1.0.0, 30/06/1998    first release
 *
 ************************************************************************************/
static Boolean PerformLMSARM( int outputs[ ], int inputs[ ], unsigned int nInputs, int coeffs[ ], unsigned int nCoeffs, int desired[ ], unsigned int adaptRate )
{
	int	*coeffsStates ;

	if( ( coeffsStates = ( int * )calloc( ( nCoeffs*2 ), sizeof( int ) ) ) == NULL ) {
		fprintf( stderr, "Failure to create array for coefficients and states, aborting.\n\n" ) ;
		return FALSE ;
	}
	
	LMS_PowerUp( coeffsStates, coeffs, nCoeffs ) ;
	LMS( outputs, inputs, nInputs, desired, adaptRate, nCoeffs, coeffsStates ) ;
	LMS_PowerDown( coeffs, coeffsStates, nCoeffs ) ;
	
	free( ( void * ) coeffsStates ) ;

	return TRUE ;
}
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -