hp50.c revision b676a05348e4c516fa8b57e33b10548e6142c3f8
1/*
2 ** Copyright 2003-2010, VisualOn, Inc.
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 **     http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16
17/***********************************************************************
18*      File: hp50.c                                                     *
19*                                                                       *
20*	   Description:                                                 *
21* 2nd order high pass filter with cut off frequency at 31 Hz.           *
22* Designed with cheby2 function in MATLAB.                              *
23* Optimized for fixed-point to get the following frequency response:    *
24*                                                                       *
25*  frequency:     0Hz    14Hz  24Hz   31Hz   37Hz   41Hz   47Hz         *
26*  dB loss:     -infdB  -15dB  -6dB   -3dB  -1.5dB  -1dB  -0.5dB        *
27*                                                                       *
28* Algorithm:                                                            *
29*                                                                       *
30*  y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2]                         *
31*                   + a[1]*y[i-1] + a[2]*y[i-2];                        *
32*                                                                       *
33*  Word16 b[3] = {4053, -8106, 4053};       in Q12                      *
34*  Word16 a[3] = {8192, 16211, -8021};       in Q12                     *
35*                                                                       *
36*  float -->   b[3] = {0.989501953, -1.979003906,  0.989501953};        *
37*              a[3] = {1.000000000,  1.978881836, -0.979125977};        *
38************************************************************************/
39
40#include "typedef.h"
41#include "basic_op.h"
42#include "oper_32b.h"
43#include "cnst.h"
44#include "acelp.h"
45
46/* filter coefficients  */
47static Word16 b[3] = {4053, -8106, 4053};  /* Q12 */
48static Word16 a[3] = {8192, 16211, -8021}; /* Q12 (x2) */
49
50/* Initialization of static values */
51
52void Init_HP50_12k8(Word16 mem[])
53{
54	Set_zero(mem, 6);
55}
56
57
58void HP50_12k8(
59		Word16 signal[],                      /* input/output signal */
60		Word16 lg,                            /* lenght of signal    */
61		Word16 mem[]                          /* filter memory [6]   */
62	      )
63{
64	Word16 x2;
65	Word16 y2_hi, y2_lo, y1_hi, y1_lo, x0, x1;
66	Word32 L_tmp;
67	Word32 num;
68
69	y2_hi = *mem++;
70	y2_lo = *mem++;
71	y1_hi = *mem++;
72	y1_lo = *mem++;
73	x0 = *mem++;
74	x1 = *mem;
75	num = (Word32)lg;
76	do
77	{
78		x2 = x1;
79		x1 = x0;
80		x0 = *signal;
81		/* y[i] = b[0]*x[i] + b[1]*x[i-1] + b140[2]*x[i-2]  */
82		/* + a[1]*y[i-1] + a[2] * y[i-2];  */
83		L_tmp = 8192 ;                    /* rounding to maximise precision */
84		L_tmp += y1_lo * a[1];
85		L_tmp += y2_lo * a[2];
86		L_tmp = L_tmp >> 14;
87		L_tmp += (y1_hi * a[1] + y2_hi * a[2] + (x0 + x2) * b[0] + x1 * b[1]) << 1;
88		L_tmp <<= 2;           /* coeff Q12 --> Q13 */
89		y2_hi = y1_hi;
90		y2_lo = y1_lo;
91		y1_hi = (Word16)(L_tmp>>16);
92		y1_lo = (Word16)((L_tmp & 0xffff)>>1);
93		*signal++ = extract_h((L_add((L_tmp<<1), 0x8000)));
94	}while(--num !=0);
95
96	*mem-- = x1;
97	*mem-- = x0;
98	*mem-- = y1_lo;
99	*mem-- = y1_hi;
100	*mem-- = y2_lo;
101	*mem-- = y2_hi;
102
103	return;
104}
105
106
107