TA的每日心情 | 难过 2020-4-23 15:10 |
---|
签到天数: 37 天 [LV.5]常住居民I
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
各位大神,我有一个疑问。fir的输出序列长度按道理是输入序列的长度+滤波器的阶数。可最近看了一个代码,它的输出序列长度冒似与输入序列长度相同,恳请指点一下。
% W0 B8 _5 Y& D6 H5 l滤波函数:3 T8 p+ u2 _& t, Q& K. j* c
#define NUM_TAPS 48
- n& z% P& w8 Y#define NUM_DATA 80* t) h' d d& V' X+ M
" o' ~% i, P, p
# D8 [( a; `+ k+ [/ ?void floatPointFir(float *x, float *h, short order, float *y, float *w)
- k+ [3 H6 H) |% @! _. v* M3 w{) j& R- s, `7 F1 z) Z0 D5 r+ \$ X# W
short i;3 o* ~- ?* o# y3 ^
float sum;
) f$ t& ~, a: y+ }- K, @ w[0] = *x++; // Get the current data to delay line4 C2 r1 {/ F4 C! N2 P
for (sum=0, i=0; i<order; i++) // FIR filter processing8 S6 ^( \7 D+ E2 G: ]
{
, {0 z% E0 q* L sum += h * w;3 T1 C$ O4 q; Y9 S+ D n8 @
}
" n1 P7 J4 k2 t% a5 q *y++ = sum; // Save filter output2 J! p" }. `" X
for (i=order-1; i>0; i--) // Update data delay line
, i1 |2 j4 Y& H l6 n1 ` {
0 ~: Y9 H4 ?8 r3 [: b w = w[i-1] ;
! m; C5 R3 u& p) _$ y# S }/ _' b4 ?3 M' P7 ~: y
}
: n, g: P- O( E6 ]7 M
: g0 u* o4 {# H/ W" o; o: y4 ~5 e
5 U9 c9 D# b% c9 t+ p测试代码:
3 I5 ~/ L: d( d' h, L" s' L& Rfloat w[NUM_TAPS];) Q) q. W% Z2 ?, G3 X& v9 c" G
void main()2 U7 h) n0 L4 |/ o! s
{/ n& n0 L3 w( y
FILE *fpIn,*fpOut;* |( e& W7 d& V
short i;
P& g% T3 s' l9 |5 m0 R3 u char temp[2];0 Y5 t0 S3 c5 a% t+ n) c
float x, // Input data
( _) A9 `! w+ v! X" |! L' V, @ y; // Output data
; B; Y A' u/ c
4 t' X" L* h' ~+ h4 H fpIn = fopen("..\\data\\input.pcm", "rb");
, ~; o/ _5 `, Q2 B5 z fpOut = fopen("..\\data\\output.pcm", "wb");; Q+ U3 x' I9 x9 N! W' h& t$ _
if (fpIn == NULL)
+ h; K9 j8 r' r9 H, G4 h {
3 w3 J& o, f5 ]3 ~- Y) N# | printf("Can't open input file\n");- S( ~! A' l& Y3 t- h* E6 ^
exit(0);0 ~5 f1 B$ U0 `( I; g
}$ V' H# P2 o3 o
, l% V' W2 H# p( j- l! Z // Initialize for filtering process
# B; z3 V3 l9 G- S1 p H2 g; ? for (i=0; i<NUM_TAPS; i++)2 X. h6 [- u/ r1 \* B( _
{
8 | g' L# D3 S' R: s2 | w = 0.0;
7 `+ g! p' d+ |8 M8 h4 i }# f4 N5 h& g& |: D: X
// Begin filtering the data
+ n% R) r2 I5 w6 ~7 v G) H while (fread(&temp, sizeof(char), 2, fpIn) == 2)
( T; k& r$ g# P {- w7 w1 b% V4 t1 n
x = (float)((temp[1]<<8)|(temp[0]&0xff));8 u0 D; k& J" h
// Filter the data x and save output y
: r/ q9 A, c* r, a floatPointFir(&x, firCoefFloatingPoint, NUM_TAPS, &y, w);
* M$ `3 V W) b7 [8 Z5 R7 W3 p temp[0] = (char)((short)y&0xff);
6 x! S$ [8 N& g; U temp[1] = (char)(((short)y>>8)&0xff);; }: l s2 C0 u8 N. X
fwrite(&temp, sizeof(char), 2, fpOut);
# h% I* l/ ?0 O# K }
6 o" J8 _( i% J4 M/ E fclose(fpIn); Z: d- X+ g) S/ [2 W8 n; K' l2 u
fclose(fpOut);6 ~1 U1 m R. x# ~. v
}
- ~; L) M+ Q2 g0 \& T
) t+ r5 ^4 k+ S# F! e3 w( c7 S' f* `& N4 M
|
|