?? fir1.c
字號(hào):
/* 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;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -