From 80eabf5acb60ee1576e397b54f5086bb27648cc6 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Fri, 2 Jan 2015 13:25:36 +0100 Subject: [PATCH] normalize amplitude from avg absolute amplitude --- app/src/main/rs/decoder.rs | 11 ++++++----- app/src/main/rs/initialization.rsh | 2 +- app/src/main/rs/state.rsh | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/rs/decoder.rs b/app/src/main/rs/decoder.rs index 2c0a3f6..4932735 100644 --- a/app/src/main/rs/decoder.rs +++ b/app/src/main/rs/decoder.rs @@ -145,13 +145,14 @@ void decode(int samples) { *saved_width = 0; *saved_height = 0; for (int sample = 0; sample < samples; ++sample, ++buffer_pos) { - float amp = audio_buffer[sample] / 32768.0f; - float power = amp * amp; - if (filter(&avg_power, power) < 0.0000001f) + int amp = audio_buffer[sample]; + float avg_amp = filter(&avg_amplitude, abs(amp)); + if (avg_amp < 16.0f) continue; + float norm_amp = amp / avg_amp; - complex_t cnt_baseband = convert(&cnt_ddc, amp); - complex_t dat_baseband = convert(&dat_ddc, amp); + complex_t cnt_baseband = convert(&cnt_ddc, norm_amp); + complex_t dat_baseband = convert(&dat_ddc, norm_amp); float cnt_value = demodulate(&cnt_fmd, cnt_baseband); float dat_value = demodulate(&dat_fmd, dat_baseband); diff --git a/app/src/main/rs/initialization.rsh b/app/src/main/rs/initialization.rsh index 3a3317a..ee08ae6 100644 --- a/app/src/main/rs/initialization.rsh +++ b/app/src/main/rs/initialization.rsh @@ -82,7 +82,7 @@ void initialize(float rate, int length, int width, int height) const float dat_bandwidth = 800.0f; const float cnt_bandwidth = 200.0f; - avg_power = ema_cutoff(10.0f, sample_rate); + avg_amplitude = ema_cutoff(10.0f, sample_rate); leader_lowpass = ema_cutoff(100.0f, sample_rate); cnt_ddc = ddc(cnt_carrier, cnt_bandwidth, sample_rate); diff --git a/app/src/main/rs/state.rsh b/app/src/main/rs/state.rsh index b7fb925..d47e4e9 100644 --- a/app/src/main/rs/state.rsh +++ b/app/src/main/rs/state.rsh @@ -17,7 +17,7 @@ limitations under the License. #ifndef STATE_RSH #define STATE_RSH -static ema_t avg_power, leader_lowpass; +static ema_t avg_amplitude, leader_lowpass; static ddc_t cnt_ddc, dat_ddc; static fmd_t cnt_fmd, dat_fmd; static int current_decoder;