Skip to content

Commit

Permalink
Spectrogram: fix multiple runs
Browse files Browse the repository at this point in the history
  • Loading branch information
meee1 committed Aug 5, 2024
1 parent f99e1ce commit fa2a813
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions ExtLibs/Utilities/Spectrogram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@ public static Image<Rgba32> GenerateImage(DFLogBuffer cb, out double[] freqtout,
Console.WriteLine("GenerateImage seen ISBH");
int sensorno = (type.Contains("1") ? 0 : (type.Contains("2") ? 1 : 2));
int sensor = type.Contains("ACC") ? 0 : 1;
int Ns = -1;
int type1 = -1;
int instance = -1;

(double, (double, double)[]) cachedata;

double sample_rate = -1;
double multiplier = -1;

(double time, double d)[] data = new (double time, double d)[0];
if (!cache.TryGetValue(cb.GetHashCode() + sensorno + "" + sensor, out data))
if (!cache.TryGetValue(cb.GetHashCode() + sensorno + "" + sensor, out cachedata))
{
int Ns = -1;
int type1 = -1;
int instance = -1;
double multiplier = -1;

data = cb.GetEnumeratorType(new string[] { "ISBH", "ISBD" })
.SelectMany(
item =>
Expand Down Expand Up @@ -96,12 +100,17 @@ public static Image<Rgba32> GenerateImage(DFLogBuffer cb, out double[] freqtout,
return new (double time, double d)[0];
}).ToArray();
cache.Set(cb.GetHashCode() + sensorno + "" + sensor, data,
cache.Set(cb.GetHashCode() + sensorno + "" + sensor, (sample_rate, data),
new MemoryCacheEntryOptions()
{
AbsoluteExpirationRelativeToNow = System.TimeSpan.FromMinutes(10)
});
}
else
{
sample_rate = cachedata.Item1;
data = cachedata.Item2;
}


var bins = 10;
Expand All @@ -117,10 +126,8 @@ public static Image<Rgba32> GenerateImage(DFLogBuffer cb, out double[] freqtout,
int totalsamples = data.Count();
int count = totalsamples / N;
int done = 0;
// 50% overlap
int divisor = 4;
if (count > 2048)
divisor = 1;
// batch sampling is non continuous
int divisor = 1;
count *= divisor;
var img = new Image<Rgba32>(count, freqt.Length);
log.Debug("done and count ");
Expand Down

0 comments on commit fa2a813

Please sign in to comment.