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: hp400.c * 19 * * 20 * Description: * 21 * 2nd order high pass filter with cut off frequency at 400 Hz. * 22 * Designed with cheby2 function in MATLAB. * 23 * Optimized for fixed-point to get the following frequency response: * 24 * * 25 * frequency: 0Hz 100Hz 200Hz 300Hz 400Hz 630Hz 1.5kHz 3kHz * 26 * dB loss: -infdB -30dB -20dB -10dB -3dB +6dB +1dB 0dB * 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] = {3660, -7320, 3660}; in Q12 * 34 * Word16 a[3] = {4096, 7320, -3540}; in Q12 * 35 * * 36 * float --> b[3] = {0.893554687, -1.787109375, 0.893554687}; * 37 * a[3] = {1.000000000, 1.787109375, -0.864257812}; * 38 * * 39 ************************************************************************/ 40 41 #include "typedef.h" 42 #include "basic_op.h" 43 #include "oper_32b.h" 44 #include "acelp.h" 45 46 /* filter coefficients */ 47 static Word16 b[3] = {915, -1830, 915}; /* Q12 (/4) */ 48 static Word16 a[3] = {16384, 29280, -14160}; /* Q12 (x4) */ 49 /* Initialization of static values */ 50 51 void Init_HP400_12k8(Word16 mem[]) 52 { 53 Set_zero(mem, 6); 54 } 55 56 57 void HP400_12k8( 58 Word16 signal[], /* input signal / output is divided by 16 */ 59 Word16 lg, /* lenght of signal */ 60 Word16 mem[] /* filter memory [6] */ 61 ) 62 { 63 Word16 x2; 64 Word16 y2_hi, y2_lo, y1_hi, y1_lo, x0, x1; 65 Word32 L_tmp; 66 Word32 num; 67 y2_hi = *mem++; 68 y2_lo = *mem++; 69 y1_hi = *mem++; 70 y1_lo = *mem++; 71 x0 = *mem++; 72 x1 = *mem; 73 num = (Word32)lg; 74 do 75 { 76 x2 = x1; 77 x1 = x0; 78 x0 = *signal; 79 /* y[i] = b[0]*x[i] + b[1]*x[i-1] + b140[2]*x[i-2] */ 80 /* + a[1]*y[i-1] + a[2] * y[i-2]; */ 81 L_tmp = 8192L; /* rounding to maximise precision */ 82 L_tmp += y1_lo * a[1]; 83 L_tmp += y2_lo * a[2]; 84 L_tmp = L_tmp >> 14; 85 L_tmp += (y1_hi * a[1] + y2_hi * a[2] + (x0 + x2)* b[0] + x1 * b[1]) << 1; 86 L_tmp <<= 1; /* coeff Q12 --> Q13 */ 87 y2_hi = y1_hi; 88 y2_lo = y1_lo; 89 y1_hi = (Word16)(L_tmp>>16); 90 y1_lo = (Word16)((L_tmp & 0xffff)>>1); 91 92 /* signal is divided by 16 to avoid overflow in energy computation */ 93 *signal++ = (L_tmp + 0x8000) >> 16; 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 return; 103 } 104 105 106 107