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

📄 fir1.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的各种滤波器源码
💻 C
字号:
/*                                         fir1.c -- (part) 
 * 
 * convolution of two 8 bit integer arrays a, b of length 400 
 * and 8 respectively.
 * 
 * Rough pictorial description of the process.
 * 
 *  
 *
 *              |--------|--------|--------|--------|  a[32]
 *
 *              |--------|                             b[8]
 *
 *   
 *
 *              |--------|--------|--------|--------|  a
 *
 *     |--------|                                      time reversed b
 *
 *
 * 
 *              |--------|--------|--------|--------|  a
 *
 *                 |--------|                          time reversed 
 *                                                     and sliding b
 *
 * Increase the length of array a so that vector of length 8 could be 
 * prepended and appended. With this additional zeros, separate handling 
 * of beginning and end of data is avoided 
 *
 *	|00000000|---------|---------|---------|---------|00000000|
 *
 *		 |<--   Original length 400 array a  --->|
 *
 * These arrays will hold the result of convolutions. Actual required 
 * output array length = 400 + 8 - 1 = 493, but our modified algorithm 
 * will calculate one unnecessary element. To handle this, output 
 * array length has been increased by 1
 */

#include <ops/custom_defs.h>

#define NROF_SAMPLES	400

void
initialize( char *a, char *b )
{
	int	i;
	
	for(i = 0; i < 8; i++)
		b[i] = i - 4;

	for(i = 0; i < 8; i++)
		a[i] = 0;                /* Prepend zeros */
		
	for(i = 8; i < NROF_SAMPLES; i++)
		a[i] = i - 24;           /* Actual data   */
		
	for(i = NROF_SAMPLES; i < NROF_SAMPLES + 8; i++)
		a[i] = 0;                /* Append zeros  */
}

/* 
 *        +++  Direct Convolution   +++
 *  c[k] = a[k] * b[k]
 *       = sum_{j = 0}^{j = 7} b[j]a[k-j]           
 */

void
direct_convolution( char *a, char *b, int *c )
{
	int        k, j;

	for(k = 0; k < NROF_SAMPLES; k++) {
	
		c[k] = 0;
		
		for(j = 0; j < 8; j++)
			c[k] += b[j] * a[k - j];
	}
}

int 
main( void )
{
	char	a[8+NROF_SAMPLES], b[8];
	int 	c[NROF_SAMPLES];

	initialize( a, b );

	direct_convolution( a + 8, b, c );	/* Note data starts at a + 8 */
 
	return 0;
}

⌨️ 快捷键说明

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