From 540161c11527b8dc91754b5ed41cad43367f8529 Mon Sep 17 00:00:00 2001 From: Christophe Favergeon Date: Wed, 14 Jun 2023 09:34:16 +0200 Subject: [PATCH] Corrected issue #106 Energy saturation in fixed point for lms norm --- Source/FilteringFunctions/arm_lms_norm_q15.c | 1 + Source/FilteringFunctions/arm_lms_norm_q31.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/FilteringFunctions/arm_lms_norm_q15.c b/Source/FilteringFunctions/arm_lms_norm_q15.c index b07efdda..b38c5ba3 100644 --- a/Source/FilteringFunctions/arm_lms_norm_q15.c +++ b/Source/FilteringFunctions/arm_lms_norm_q15.c @@ -116,6 +116,7 @@ void arm_lms_norm_q15( /* Update the energy calculation */ energy -= (((q31_t) x0 * (x0)) >> 15); energy += (((q31_t) in * (in)) >> 15); + energy = (q15_t) __SSAT(energy, 16); /* Set the accumulator to zero */ acc = 0; diff --git a/Source/FilteringFunctions/arm_lms_norm_q31.c b/Source/FilteringFunctions/arm_lms_norm_q31.c index 6375d8ff..ff266a32 100644 --- a/Source/FilteringFunctions/arm_lms_norm_q31.c +++ b/Source/FilteringFunctions/arm_lms_norm_q31.c @@ -115,8 +115,9 @@ void arm_lms_norm_q31( /* Update the energy calculation */ energy = (q31_t) ((((q63_t) energy << 32) - (((q63_t) x0 * x0) << 1)) >> 32); - energy = (q31_t) (((((q63_t) in * in) << 1) + (energy << 32)) >> 32); - + energy = ((((q63_t) in * in) << 1) + (energy << 32)) >> 32; + energy = clip_q63_to_q31(energy); + /* Set the accumulator to zero */ acc = 0;