From e1e43678c98e065340d46adf0a849f618e93df97 Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Sat, 13 Feb 2021 15:30:14 -0800 Subject: [PATCH 1/2] Fix issue preventing BPH below 14400 from working Periods (two beats) longer than 500 ms were rejected as too long. This effectively limits the low end of BPH to 14400. Any slower and the correct period length is greater than 500 ms, e.g. 12000 BPH is a 600 ms period. Change the limit to be 20% slower than the nominal value for the BPH. If the BPH is set, then use that, when BPH is guessed, use MIN_BPH. A MIN_BPH of 12000 will increases the max period to 720 ms when guessing. It could be longer if one were able to set a slower than MIN_BPH period length. --- src/algo.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/algo.c b/src/algo.c index 1c744cb..36f1601 100644 --- a/src/algo.c +++ b/src/algo.c @@ -898,8 +898,12 @@ static void compute_cal(struct calibration_data *cd) void process(struct processing_buffers *p, int bph, double la, int light) { prepare_data(p, !light); + p->ready = !compute_period(p,bph); - if(p->ready && p->period >= p->sample_rate / 2) { + /* Limit to 20% greater when period is known, or 500 ms when guessing period */ + const int min_bph = bph ? bph : MIN_BPH; + const int max_period = (int)(1.2 * 3600 * 2) * p->sample_rate / min_bph; + if(p->ready && p->period >= max_period) { debug("Detected period too long\n"); p->ready = 0; } @@ -907,6 +911,7 @@ void process(struct processing_buffers *p, int bph, double la, int light) debug("abort after compute_period()\n"); return; } + prepare_waveform(p); p->ready = !compute_parameters(p); if(!p->ready) { From 5fa7289ba1be6d745bb63341bd4dcc3cb9ef67b5 Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Tue, 13 Apr 2021 01:23:50 -0700 Subject: [PATCH 2/2] Lower min BPH to 8100 Allow lower BPH values. Create another setting that affects the BPH guessing code so it doesn't get confused by fractions of faster beats. Lowest value is 2.25 Hz or 8100 BPH. Lower rates do not work well or at all. Tg uses a minimum 2 second detection window and needs to see two periods in this window. So that it can see the 1st period matches the 2nd period and the time between them is about what it should be from the BPH. In order to get two complete periods (two beats each) in a 2 second window, one needs 7200 BPH. Below this and there might only be one period in the window and nothing to detect. But even at 7200, the beats at the beginning and end of the window might be cut off, so it's necessary to go a little faster to be reliable. --- src/algo.c | 2 +- src/tg.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/algo.c b/src/algo.c index 36f1601..b7d11f7 100644 --- a/src/algo.c +++ b/src/algo.c @@ -901,7 +901,7 @@ void process(struct processing_buffers *p, int bph, double la, int light) p->ready = !compute_period(p,bph); /* Limit to 20% greater when period is known, or 500 ms when guessing period */ - const int min_bph = bph ? bph : MIN_BPH; + const int min_bph = bph ? bph : TYP_BPH; const int max_period = (int)(1.2 * 3600 * 2) * p->sample_rate / min_bph; if(p->ready && p->period >= max_period) { debug("Detected period too long\n"); diff --git a/src/tg.h b/src/tg.h index 789f66c..4aedd82 100644 --- a/src/tg.h +++ b/src/tg.h @@ -57,7 +57,8 @@ #define PAPERSTRIP_ZOOM_CAL 100 #define PAPERSTRIP_MARGIN .2 -#define MIN_BPH 12000 +#define MIN_BPH 8100 +#define TYP_BPH 12000 #define MAX_BPH 72000 #define DEFAULT_BPH 21600 #define MIN_LA 10 // deg