1 /* ======================================================================= */
2 /* TEXAS INSTRUMENTS, INC. */
3 /* */
4 /* DSPLIB DSP Signal Processing Library */
5 /* */
6 /* This library contains proprietary intellectual property of Texas */
7 /* Instruments, Inc. The library and its source code are protected by */
8 /* various copyrights, and portions may also be protected by patents or */
9 /* other legal protections. */
10 /* */
11 /* This software is licensed for use with Texas Instruments TMS320 */
12 /* family DSPs. This license was provided to you prior to installing */
13 /* the software. You may review this license by consulting the file */
14 /* TI_license.PDF which accompanies the files in this library. */
15 /* */
16 /* ----------------------------------------------------------------------- */
17 /* */
18 /* DSP_iir.c -- Real IIR Filter */
19 /* Intrinsic C Implementation */
20 /* */
21 /* REV 0.0.1 */
22 /* */
23 /* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ */
24 /* */
25 /* */
26 /* Redistribution and use in source and binary forms, with or without */
27 /* modification, are permitted provided that the following conditions */
28 /* are met: */
29 /* */
30 /* Redistributions of source code must retain the above copyright */
31 /* notice, this list of conditions and the following disclaimer. */
32 /* */
33 /* Redistributions in binary form must reproduce the above copyright */
34 /* notice, this list of conditions and the following disclaimer in the */
35 /* documentation and/or other materials provided with the */
36 /* distribution. */
37 /* */
38 /* Neither the name of Texas Instruments Incorporated nor the names of */
39 /* its contributors may be used to endorse or promote products derived */
40 /* from this software without specific prior written permission. */
41 /* */
42 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
43 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
44 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */
45 /* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
46 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
47 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
48 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
49 /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */
50 /* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
51 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */
52 /* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
53 /* */
54 /* ======================================================================= */
56 #pragma CODE_SECTION(DSP_iir, ".text:optimized");
58 #include "DSP_iir.h"
60 void DSP_iir (
61 short *restrict r1, /* Pointer to real output data used/stored */
62 const short *restrict x, /* Pointer to real input data */
63 short *restrict r2, /* Pointer to real output data stored */
64 const short *restrict h2, /* Pointer to 5 Moving-average real filter coefficients */
65 const short *restrict h1, /* Pointer to 4 Autoregressive real filter coefficients */
66 int nr /* Holds the value of number of real output samples */
67 )
68 {
70 int sum1,sum2, sum3, sum4, sum5, i;
71 int h2_3_h1_4, x_5_r_4;
73 h2_3_h1_4 = _pack2(h2[3],h1[4]);
75 sum1 = ( h2[0] * x[4]
76 + h2[1] * x[3] - h1[1] * r1[3]
77 + h2[2] * x[2] - h1[2] * r1[2]
78 + h2[3] * x[1] - h1[3] * r1[1]
79 + h2[4] * x[0] - h1[4] * r1[0]
80 );
82 sum2 = ( h2[1] * x[4]
83 + h2[2] * x[3] - h1[2] * r1[3]
84 + h2[3] * x[2] - h1[3] * r1[2]
85 + h2[4] * x[1] - h1[4] * r1[1]
86 );
88 sum3 = ( h2[2] * x[4]
89 + h2[3] * x[3] - h1[3] * r1[3]
90 + h2[4] * x[2] - h1[4] * r1[2]
91 );
93 sum4 = ( h2[3] * x[4]
94 + h2[4] * x[3] - h1[4] * r1[3]
95 );
97 sum5 = ( h2[4] * x[4]
98 );
100 #pragma MUST_ITERATE(1);
102 for (i = 0; i < nr-1; i++ ) {
104 r1[i+4] = sum1 >> 15;
105 r2[i] = r1[i+4];
106 x_5_r_4 = _pack2(x[i+5], r1[i+4]);
108 sum1 = sum2 + _mpy (h2[0], x[i+5]) - _mpy (h1[1], r1[i+4]);
109 sum2 = sum3 + _mpy (h2[1], x[i+5]) - _mpy (h1[2], r1[i+4]);
110 sum3 = sum4 + _mpy (h2[2], x[i+5]) - _mpy (h1[3], r1[i+4]);
111 sum4 = sum5 + _dotpn2(h2_3_h1_4, x_5_r_4);
112 sum5 = _mpy (h2[4], x[i+5]);
113 }
114 r1[nr+3] = sum1 >> 15;
115 r2[nr-1] = r1[nr+3];
117 }
119 /* ======================================================================= */
120 /* End of file: Dsp_iir.c */
121 /* ----------------------------------------------------------------------- */
122 /* Copyright (c) 2011 Texas Instruments, Incorporated. */
123 /* All Rights Reserved. */
124 /* ======================================================================= */