Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Michael Niedermayer <michael@niedermayer.cc>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH 7/9] avradio/sdr: Compute and use detection histogram
Date: Fri,  7 Jul 2023 19:22:22 +0200
Message-ID: <20230707172224.2368067-7-michael@niedermayer.cc> (raw)
In-Reply-To: <20230707172224.2368067-1-michael@niedermayer.cc>

By analyzing the behavior of the detectability of stations with
different SDR settings we can separate some SDR artifacts from
weak stations.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/sdr.h      |  5 +++++
 libavradio/sdrdemux.c | 36 +++++++++++++++++++++++++++++++++++-
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/libavradio/sdr.h b/libavradio/sdr.h
index 838fb1cef7..1053e45efe 100644
--- a/libavradio/sdr.h
+++ b/libavradio/sdr.h
@@ -66,6 +66,8 @@ typedef enum Modulation {
     //QAM, PSK, ...
 } Modulation;
 
+#define HISTOGRAMM_SIZE 9
+
 typedef struct Station {
     char *name;
     enum Modulation modulation;
@@ -78,6 +80,9 @@ typedef struct Station {
     int timeout;            //since how many blocks was this detectable but not detected
     int multiplex_index;    //DAB can have multiple stations on one frequency
 
+    int detection_per_mix_frequency[HISTOGRAMM_SIZE];
+    int non_detection_per_mix_frequency[HISTOGRAMM_SIZE];
+
     struct SDRStream *stream;
 } Station;
 
diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 6cb9d3b70a..1fc528317c 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -111,6 +111,23 @@ static void free_station(Station *station)
     av_free(station);
 }
 
+static inline int histogram_index(SDRContext *sdr, double f)
+{
+    f = HISTOGRAMM_SIZE*((f - sdr->block_center_freq) / sdr->sdr_sample_rate + 0.5);
+    return av_clip((int)f, 0, HISTOGRAMM_SIZE-1);
+}
+
+static int histogram_score(Station *s)
+{
+    int score = 0;
+    for(int i = 0; i<HISTOGRAMM_SIZE; i++) {
+        score +=
+             (5*s->detection_per_mix_frequency[i] > s->non_detection_per_mix_frequency[i])
+            -(5*s->detection_per_mix_frequency[i] < s->non_detection_per_mix_frequency[i]);
+    }
+    return score;
+}
+
 typedef struct FindStationContext {
     double freq;
     double range;
@@ -184,6 +201,10 @@ static int create_station(SDRContext *sdr, Station *candidate_station) {
     if (candidate_station->in_station_list)
         return 0;
 
+    // suspect looking histogram
+    if (histogram_score(candidate_station) <= 0)
+        return 0;
+
     Station *station_list[1000];
     int nb_stations = find_stations(sdr, sdr->block_center_freq, sdr->sdr_sample_rate*0.5, station_list, FF_ARRAY_ELEMS(station_list));
     for (i=0; i<nb_stations; i++) {
@@ -328,8 +349,20 @@ static void decay_stations(SDRContext *sdr)
             station->frequency + station->bandwidth/2 > sdr->block_center_freq + sdr->bandwidth/2)
             continue;
 
+        if (station->timeout)
+            station->non_detection_per_mix_frequency[histogram_index(sdr, station->frequency)] ++;
+
         if (station->in_station_list) {
-            if (station->timeout++ > STATION_TIMEOUT) {
+            int station_timeout = STATION_TIMEOUT;
+            int hs = histogram_score(station);
+
+            if (hs == 0) {
+                station_timeout = 5; //give the station a moment to be properly detected and then discard it
+            } else if(hs < 0) {
+                station_timeout = 0; //probably not a station
+            }
+
+            if (station->timeout++ > station_timeout) {
                 if (!station->stream)
                     station->in_station_list = 0;
             }
@@ -376,6 +409,7 @@ static int create_candidate_station(SDRContext *sdr, enum Modulation modulation,
     }
     station->frequency /= ++station->nb_frequency;
 
+    station->detection_per_mix_frequency[histogram_index(sdr, freq)] ++;
     station->modulation   = modulation;
     station->bandwidth    = bandwidth;
     station->bandwidth_p2 = bandwidth_p2;
-- 
2.31.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2023-07-07 17:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-07 17:22 [FFmpeg-devel] [PATCH 1/9] avradio/sdr: use AVTree for candidate stations Michael Niedermayer
2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 2/9] avradio/sdr: Consolidate candidate station entries Michael Niedermayer
2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 3/9] avradio/sdr: consolidate the candidate station list with the main list Michael Niedermayer
2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 4/9] avradio/sdr: Eliminate station list Michael Niedermayer
2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 5/9] avradio/sdr: Allow user to adjust FM/AM thresholds Michael Niedermayer
2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 6/9] avradio/sdrdemux: count timeout irrespective of a station being active Michael Niedermayer
2023-07-07 17:22 ` Michael Niedermayer [this message]
2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 8/9] avradio/sdrdemux: increase the FM station frequency tolerance Michael Niedermayer
2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 9/9] avradio/sdrdemux: Use 2 differnt FM station detectors Michael Niedermayer
2023-07-08 15:42 ` [FFmpeg-devel] [PATCH 1/9] avradio/sdr: use AVTree for candidate stations Michael Niedermayer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230707172224.2368067-7-michael@niedermayer.cc \
    --to=michael@niedermayer.cc \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git