00001 /*This file is prepared for Doxygen automatic documentation generation.*/ 00015 /* Copyright (c) 2009 Atmel Corporation. All rights reserved. 00016 * 00017 * Redistribution and use in source and binary forms, with or without 00018 * modification, are permitted provided that the following conditions are met: 00019 * 00020 * 1. Redistributions of source code must retain the above copyright notice, this 00021 * list of conditions and the following disclaimer. 00022 * 00023 * 2. Redistributions in binary form must reproduce the above copyright notice, 00024 * this list of conditions and the following disclaimer in the documentation 00025 * and/or other materials provided with the distribution. 00026 * 00027 * 3. The name of Atmel may not be used to endorse or promote products derived 00028 * from this software without specific prior written permission. 00029 * 00030 * 4. This software may only be redistributed and used in connection with an Atmel 00031 * AVR product. 00032 * 00033 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 00034 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00035 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 00036 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 00037 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00038 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00039 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00040 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00041 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00042 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00043 * 00044 */ 00045 #include "dsp.h" 00046 00047 #define WIN_BLACK_A0 0.42 00048 #define WIN_BLACK_A1 0.5 00049 #define WIN_BLACK_A2 0.08 00050 00051 #if defined(FORCE_ALL_GENERICS) || \ 00052 defined(FORCE_GENERIC_WIN16_BLACK) || \ 00053 !defined(TARGET_SPECIFIC_WIN16_BLACK) 00054 00055 // Blackman 00056 // w(n) = a0 - a1*cos(2*PI*n/(N-1)) + a2*cos(4*PI*n/(N-1)) 00057 // N = signal width 00058 // a0 = 0.42 00059 // a1 = 0.5 00060 // a2 = 0.08 00061 // Constraints: size > 1 00062 void dsp16_win_black(dsp16_t *vect1, int size) 00063 { 00064 dsp16_t s, t, w; 00065 // To avoid a avr32-gcc 4.12 bug 00066 volatile S32 temp32; 00067 int i; 00068 00069 // Initialization 00070 t = DSP16_Q(0.); 00071 // Calculation of 2/(N-1) <- because a cos is in the range [-1; 1], 00072 // therefore -1 equals -PI and 1, PI. 00073 s = (DSP16_Q(1.)/(size - 1)) << 1; 00074 00075 // Compute the window 00076 for(i=0; i<(size >> 1); i++) 00077 { 00078 w = DSP16_Q(WIN_BLACK_A0); 00079 00080 temp32 = DSP16_Q(WIN_BLACK_A1); 00081 temp32 *= dsp16_op_cos(t); 00082 temp32 >>= DSP16_QB; 00083 w -= temp32; 00084 00085 temp32 = DSP16_Q(WIN_BLACK_A2); 00086 temp32 *= dsp16_op_cos(t << 1); 00087 temp32 >>= DSP16_QB; 00088 w += temp32; 00089 00090 vect1[i] = w; 00091 vect1[size-i-1] = w; 00092 t += s; 00093 } 00094 00095 // If the size is odd 00096 if (size & 1) 00097 vect1[size >> 1] = DSP16_Q(1.); 00098 } 00099 00100 #endif 00101 00102 #if defined(FORCE_ALL_GENERICS) || \ 00103 defined(FORCE_GENERIC_WIN32_BLACK) || \ 00104 !defined(TARGET_SPECIFIC_WIN32_BLACK) 00105 00106 void dsp32_win_black(dsp32_t *vect1, int size) 00107 { 00108 dsp32_t s, t, w; 00109 S64 temp64; 00110 int i; 00111 00112 // Initialization 00113 t = DSP32_Q(0.); 00114 // Calculation of 2/(N-1) <- because a cos is in the range [-1; 1], 00115 // therefore -1 equals -PI and 1, PI. 00116 s = (DSP32_Q(1.)/(size - 1)) << 1; 00117 00118 // Compute the window 00119 for(i=0; i<(size >> 1); i++) 00120 { 00121 w = DSP32_Q(WIN_BLACK_A0); 00122 00123 temp64 = DSP32_Q(WIN_BLACK_A1); 00124 temp64 *= dsp32_op_cos(t); 00125 temp64 >>= DSP32_QB; 00126 w -= temp64; 00127 00128 temp64 = DSP32_Q(WIN_BLACK_A2); 00129 temp64 *= dsp32_op_cos(t << 1); 00130 temp64 >>= DSP32_QB; 00131 w += temp64; 00132 00133 vect1[i] = w; 00134 vect1[size-i-1] = w; 00135 t += s; 00136 } 00137 00138 // If the size is odd 00139 if (size & 1) 00140 vect1[size >> 1] = DSP32_Q(1.); 00141 } 00142 00143 #endif