TA的每日心情 | 难过 2020-4-23 15:10 |
---|
签到天数: 37 天 [LV.5]常住居民I
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
各位大神,我有一个疑问。fir的输出序列长度按道理是输入序列的长度+滤波器的阶数。可最近看了一个代码,它的输出序列长度冒似与输入序列长度相同,恳请指点一下。& G# M. K5 A) I5 s( M0 W: s
滤波函数:& {! _9 I& r2 i( {: `5 B
#define NUM_TAPS 484 d9 c% P; _. [: V7 }/ y
#define NUM_DATA 80+ o6 Q0 ^8 K: G
% K x9 A9 u1 \+ L4 R0 [ |' \4 q
7 v2 ?# F. m0 @4 \7 Q/ ]void floatPointFir(float *x, float *h, short order, float *y, float *w)4 e( p0 Z. l) n& d4 |- s/ ^0 ]
{
8 Q; b) r; f# P short i; \. D- F& U4 s, V& U
float sum;6 ~" {) s" K4 i* K7 c) h; C9 e
w[0] = *x++; // Get the current data to delay line% c6 |, d5 _9 t+ l
for (sum=0, i=0; i<order; i++) // FIR filter processing
, Z, z8 X8 E0 x {0 I6 Z2 V9 F: T% p; Z- _
sum += h * w;
5 `, o6 a5 ]! W. Q }* y, b! S1 w x# r7 C: P
*y++ = sum; // Save filter output
7 W8 m4 F8 Y. H3 X/ \# J for (i=order-1; i>0; i--) // Update data delay line
6 q9 c3 f+ _4 y* I0 {. H# a$ ^3 j {
# ^+ l% _: N" ^# ^ w = w[i-1] ;
9 U* U' C( A/ @, R8 U8 A) q }9 N. H( s2 g% z7 c' [$ I! q
}
0 w i! C r* r+ G. W* {7 e6 z' j. a5 p/ Z/ }( G
$ z' I) f* `3 D" |6 Q% f h# g测试代码:# L" o- D+ U5 [1 V, l3 G+ B
float w[NUM_TAPS];
, U! M, a Z' {( e: a' I% K3 c) svoid main()& N8 {, C. w$ G; Q( x
{
# l7 t# ^2 L8 V& v FILE *fpIn,*fpOut;9 Z: }( U6 ]" ~8 X% {
short i;$ v/ J" `" U, `7 |1 }0 y
char temp[2];/ A. @ t4 f6 i g& _8 |% c6 z
float x, // Input data
, ~. q, _& D' x8 |& p y; // Output data) Z5 A/ F+ K0 {" F( s) q. V
( w" F& t) e+ t: X, I fpIn = fopen("..\\data\\input.pcm", "rb"); 4 z7 Y' y z$ [1 u
fpOut = fopen("..\\data\\output.pcm", "wb");
, y' y8 o5 }2 ~8 } if (fpIn == NULL)$ q% \9 J# ~ |% D5 [* u
{! V$ p- L* [, u, S8 z9 W. s& q
printf("Can't open input file\n");
' G8 ]4 {6 d, R: Q- W! z5 l- V exit(0);
" s; X( G' y9 @5 o7 h }8 ?, ?- a% K+ m7 V& }; h
$ r4 q+ ^5 q5 S0 U# v
// Initialize for filtering process0 v/ T" O6 ]: Y" f g. \6 P; l' w
for (i=0; i<NUM_TAPS; i++)4 N4 s2 u# Q) P5 e0 s, W$ n
{3 _& s' H9 t7 b4 v9 f" h; S' ]
w = 0.0;" t( d% B E& s5 q: F
}
4 q* W, }9 u. {2 `& H6 | // Begin filtering the data% O& W3 d R8 }( V# V# t- S' N
while (fread(&temp, sizeof(char), 2, fpIn) == 2)
* V4 X+ M6 s. @8 |8 V+ [6 { {
Y( w5 v# _3 J6 m+ R x = (float)((temp[1]<<8)|(temp[0]&0xff));
% S, Y& c; o2 Y6 ` // Filter the data x and save output y
$ a- b) _( G- Z9 E5 z floatPointFir(&x, firCoefFloatingPoint, NUM_TAPS, &y, w);4 F' r2 V* ^4 G) z; J: i# L5 {; [0 U
temp[0] = (char)((short)y&0xff);- h; l% D" A# g5 b" O" Z5 e# \: N N
temp[1] = (char)(((short)y>>8)&0xff);
. N. [( b6 G/ }9 I2 M fwrite(&temp, sizeof(char), 2, fpOut);/ p) P: i' j7 i. }$ M
}
2 O9 [8 Y* \: X fclose(fpIn);( \( n a* R' T/ v/ ^. Z
fclose(fpOut);4 S# F5 |1 g. t
}
% F4 G8 A y _; O. j% J4 v$ |- \$ G( l
2 y/ v1 X# @0 q8 `
|
|