Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ka9q committed Apr 11, 2023
1 parent eb23a8a commit bd5ef4b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
4 changes: 4 additions & 0 deletions id.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# $Id: id.txt,v 1.69 2023/02/01 23:54:09 karn Exp $
2500 WWV
3330 CHU
4724 Skyking
5000 WWV
7850 CHU
8992 Skyking
10000 WWV
11175 Skyking
14670 CHU
15000 WWV
15016 Skyking
20000 WWV
25000 WWV
26965 CB channel 1
Expand Down
28 changes: 18 additions & 10 deletions spectrum.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,20 @@ void *demod_spectrum(void *arg){
goto quit;
}

if(demod->spectrum.bin_data == NULL)
demod->spectrum.bin_data = calloc(demod->spectrum.bin_count,sizeof(*demod->spectrum.bin_data));
// If it's already allocated (why should it be?) we don't know how big it is
if(demod->spectrum.bin_data != NULL)
FREE(demod->spectrum.bin_data);
demod->spectrum.bin_data = calloc(demod->spectrum.bin_count,sizeof(*demod->spectrum.bin_data));

set_freq(demod,demod->tune.freq); // retune front end if needed to cover requested bandwidth

float tc = 0; // time constant cache, let it be set in the first iteration
float smooth = 1;
// Do first update with smooth == 1 so we don't have to wait for an initial exponential rise
while(!demod->terminate){

if(downconvert(demod) == -1)
break; // received terminate

if(demod->spectrum.integrate_tc <= 0)
demod->spectrum.integrate_tc = 5; // Force reasonable value of 5 sec

// https://en.wikipedia.org/wiki/Exponential_smoothing#Time constant
// smooth = 1 - exp(-blocktime/tc)
// expm1(x) = exp(x) - 1 (to preserve precision)
float const smooth = -expm1f(-Blocktime / (1000 * demod->spectrum.integrate_tc)); // Blocktime is in millisec!
int binp = 0;
for(int i=0; i < demod->spectrum.bin_count; i++){ // For each noncoherent integration bin above center freq
float p = 0;
Expand All @@ -88,6 +85,17 @@ void *demod_spectrum(void *arg){
// Exponential smoothing
demod->spectrum.bin_data[i] += smooth * (p - demod->spectrum.bin_data[i]);
}
if(tc == 0 || demod->spectrum.integrate_tc != tc){
// first time through, or value has changed; recalculate smoothing factor
if(isnan(demod->spectrum.integrate_tc) || demod->spectrum.integrate_tc <= 0)
demod->spectrum.integrate_tc = 5; // Force reasonable value of 5 sec

tc = demod->spectrum.integrate_tc; // Update cache copy
// https://en.wikipedia.org/wiki/Exponential_smoothing#Time constant
// smooth = 1 - exp(-blocktime/tc)
// expm1(x) = exp(x) - 1 (to preserve precision)
smooth = -expm1f(-Blocktime / (1000 * tc)); // Blocktime is in millisec!
}
}
quit:;
FREE(demod->spectrum.bin_data);
Expand Down

0 comments on commit bd5ef4b

Please sign in to comment.