]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ep-processor-libraries/dsplib.git/blob - ti/dsplib/src/DSP_fir_cplx/c64P/DSP_fir_cplx_cn.c
DSPLIB: optimized signal processing functions for TI DSPs
[ep-processor-libraries/dsplib.git] / ti / dsplib / src / DSP_fir_cplx / c64P / DSP_fir_cplx_cn.c
1 /* ======================================================================= */
2 /* DSP_fir_cplx_cn.c -- Complex FIR Filter                                 */
3 /*                      Natural C Implementation                           */
4 /*                                                                         */
5 /* Rev 0.0.1                                                               */
6 /*                                                                         */
7 /*  Usage                                                                  */
8 /*     This routine is C-callable and can be called as:                    */
9 /*                                                                         */
10 /*     void DSP_fir_cplx_cn (                                              */
11 /*         const short *restrict x,                                        */
12 /*         const short *restrict h,                                        */
13 /*         short *restrict r,                                              */
14 /*         int nh,                                                         */
15 /*         int nr,                                                         */
16 /*     )                                                                   */
17 /*                                                                         */
18 /*     x[2*(nr+nh-1)] : Complex input data. x must point to x[2*(nh-1)].   */
19 /*     h[2*nh]        : Complex coefficients (in normal order).            */
20 /*     r[2*nr]        : Complex output data.                               */
21 /*     nh             : Number of complex coefficients.                    */
22 /*     nr             : Number of complex output samples.                  */
23 /*                                                                         */
24 /*  Description                                                            */
25 /*      This complex FIR computes nr complex output samples using nh       */
26 /*      complex coefficients. It operates on 16-bit data with a 32-bit     */
27 /*      accumulate. Each array consists of an even and odd term with even  */
28 /*      terms representing the real part of the element and the odd terms  */
29 /*      the imaginary part. The pointer to input array x must point to the */
30 /*      (nh)th complex sample, i.e. element 2*(nh-1), upon entry to the    */
31 /*      function. The coefficients are expected in normal order.           */
32 /*                                                                         */
33 /*  Assumptions                                                            */
34 /*     Arrays x, h, and r do not overlap                                   */
35 /*                                                                         */
36 /* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/  */ 
37 /*                                                                         */
38 /*                                                                         */
39 /*  Redistribution and use in source and binary forms, with or without     */
40 /*  modification, are permitted provided that the following conditions     */
41 /*  are met:                                                               */
42 /*                                                                         */
43 /*    Redistributions of source code must retain the above copyright       */
44 /*    notice, this list of conditions and the following disclaimer.        */
45 /*                                                                         */
46 /*    Redistributions in binary form must reproduce the above copyright    */
47 /*    notice, this list of conditions and the following disclaimer in the  */
48 /*    documentation and/or other materials provided with the               */
49 /*    distribution.                                                        */
50 /*                                                                         */
51 /*    Neither the name of Texas Instruments Incorporated nor the names of  */
52 /*    its contributors may be used to endorse or promote products derived  */
53 /*    from this software without specific prior written permission.        */
54 /*                                                                         */
55 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS    */
56 /*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT      */
57 /*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR  */
58 /*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT   */
59 /*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,  */
60 /*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT       */
61 /*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  */
62 /*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  */
63 /*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT    */
64 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  */
65 /*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   */
66 /*                                                                         */
67 /* ======================================================================= */
69 #pragma CODE_SECTION(DSP_fir_cplx_cn, ".text:ansi");
71 #include "DSP_fir_cplx_cn.h"
73 void DSP_fir_cplx_cn (
74     const short *restrict x,
75     const short *restrict h,
76     short       *restrict r,
77     int nh,
78     int nr
79 )
80 {
81     int i, j;
82     int imag, real;
84 #ifndef NOASSUME
85     _nassert((int) nh % 2 == 0);
86     _nassert((int) nh >= 2);
87     _nassert((int) nr % 4 == 0);
88     _nassert((int) nr >= 4);
89 #endif
91     for (i = 0; i < 2*nr; i += 2) {
92         imag = 0;
93         real = 0;
94         for (j = 0; j < 2*nh; j += 2) {
95             real += h[j+0] * x[i-j+0] - h[j+1] * x[i-j+1];
96             imag += h[j+1] * x[i-j+0] + h[j+0] * x[i-j+1];
97         }
98         r[i] = (real >> 15);
99         r[i+1] = (imag >> 15);
100     }
103 /* ======================================================================= */
104 /*  End of file:  DSP_fir_cplx_cn.c                                        */
105 /* ----------------------------------------------------------------------- */
106 /*            Copyright (c) 2011 Texas Instruments, Incorporated.          */
107 /*                           All Rights Reserved.                          */
108 /* ======================================================================= */