00001 /*This file has been prepared for Doxygen automatic documentation generation.*/ 00017 /* Copyright (c) 2009 Atmel Corporation. All rights reserved. 00018 * 00019 * Redistribution and use in source and binary forms, with or without 00020 * modification, are permitted provided that the following conditions are met: 00021 * 00022 * 1. Redistributions of source code must retain the above copyright notice, this 00023 * list of conditions and the following disclaimer. 00024 * 00025 * 2. Redistributions in binary form must reproduce the above copyright notice, 00026 * this list of conditions and the following disclaimer in the documentation 00027 * and/or other materials provided with the distribution. 00028 * 00029 * 3. The name of Atmel may not be used to endorse or promote products derived 00030 * from this software without specific prior written permission. 00031 * 00032 * 4. This software may only be redistributed and used in connection with an Atmel 00033 * AVR product. 00034 * 00035 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 00036 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00037 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 00038 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 00039 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00040 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00041 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00042 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00043 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00044 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00045 * 00046 */ 00047 00048 #include "dsp.h" 00049 00050 #if defined(FORCE_ALL_GENERICS) || \ 00051 defined(FORCE_GENERIC_FILT32_LMS) || \ 00052 !defined(TARGET_SPECIFIC_FILT32_LMS) 00053 00054 #include "filt_lms.h" 00055 00056 void dsp32_filt_lms(dsp32_t *x, dsp32_t *w, int size, dsp32_t new_x, dsp32_t d, dsp32_t *y, dsp32_t *e) 00057 { 00058 int i; 00059 S64 temp; 00060 00061 x[0] = new_x; 00062 00063 temp = 0; 00064 // Performed a FIR 00065 for(i=0; i<size; i+=4) 00066 { 00067 temp += (((S64) w[i])*((S64) x[i])); 00068 temp += (((S64) w[i+1])*((S64) x[i+1])); 00069 temp += (((S64) w[i+2])*((S64) x[i+2])); 00070 temp += (((S64) w[i+3])*((S64) x[i+4])); 00071 } 00072 *y = temp >> (DSP32_QB); 00073 00074 // Error calculation 00075 *e = d - *y; 00076 00077 // Refresh the w coefficients 00078 for(i=0; i<size; i+=4) 00079 { 00080 w[i] += ((((S64) *e)*((S64) x[i]))) >> (DSP_LMS_MU - 1 + DSP32_QB); 00081 w[i+1] += ((((S64) *e)*((S64) x[i+1]))) >> (DSP_LMS_MU - 1 + DSP32_QB); 00082 w[i+2] += ((((S64) *e)*((S64) x[i+2]))) >> (DSP_LMS_MU - 1 + DSP32_QB); 00083 w[i+3] += ((((S64) *e)*((S64) x[i+3]))) >> (DSP_LMS_MU - 1 + DSP32_QB); 00084 } 00085 00086 // Shift the circular buffer 00087 for(i=size-1; i>0; i-=4) 00088 { 00089 x[i] = x[i-1]; 00090 x[i-1] = x[i-2]; 00091 x[i-2] = x[i-3]; 00092 x[i-3] = x[i-4]; 00093 } 00094 } 00095 00096 #endif