Skip to content

Commit

Permalink
mid-point
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustify committed Jan 29, 2024
1 parent 0ff0d98 commit df10da4
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 20 deletions.
8 changes: 4 additions & 4 deletions SdrsDecoder.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static void Main(string[] args)
{
try
{
var source = "raw3.wav";
var source = "raw.wav";

if (args.Length > 0)
{
Expand Down Expand Up @@ -87,7 +87,7 @@ static void Main(string[] args)
//}

var chain = new PocsagChain(
2400,
1200,
file.WaveFormat.SampleRate,
(message) =>
{
Expand All @@ -100,7 +100,7 @@ static void Main(string[] args)

chain.Process(samples.ToArray(), writeSample: ws);

using (var writer = new WaveFileWriter("debug.wav", new WaveFormat(37500, 4)))
using (var writer = new WaveFileWriter("debug.wav", new WaveFormat(12000, 4)))
{
foreach (var ss in debug.ToArray())
{
Expand All @@ -115,7 +115,7 @@ static void Main(string[] args)
}

Console.WriteLine("Done.");
Console.ReadKey(true);
//Console.ReadKey(true);
}
}
}
2 changes: 2 additions & 0 deletions SdrsDecoder.Plugin/SdrsDecoder.Plugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
<ItemGroup>
<Reference Include="SDRSharp.Common">
<HintPath>..\Assemblies\SDRSharp.Common.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SDRSharp.Radio">
<HintPath>..\Assemblies\SDRSharp.Radio.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>

Expand Down
41 changes: 34 additions & 7 deletions SdrsDecoder/Flex/FlexChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,35 @@ public class FlexChain : ChainBase

public bool DISABLE_FILTER = false;

private Interpolator interpolator;
private Decimator decimator;

public FlexChain(float baud, float sampleRate, Action<MessageBase> messageReceived) : base(sampleRate, messageReceived)
{
this.baud = baud;



var i = 1;
var d = 1;

if (baud == 1600)
{
i = 32;
d = 75;
}

if (baud == 3200)
{
i = 64;
d = 75;
}

var isr = sampleRate * i;
var dsr = isr / d;

//var pll = new PllDecimalPi(
// sampleRate,
// dsr,
// this.baud,
// PllUpdateType.Both,
// 0.2M,
Expand All @@ -27,23 +50,27 @@ public FlexChain(float baud, float sampleRate, Action<MessageBase> messageReceiv
// +10M
//);

var pll = new Pll(sampleRate, baud);
var pll = new Pll(dsr, baud);

filter = new ChebyFilter(this.baud, 1f, this.sampleRate);
demodulator = new Fsk2Demodulator(this.baud, this.sampleRate, pll, false);
interpolator = new Interpolator(i);
filter = new ChebyFilter(this.baud, 1f, isr);
decimator = new Decimator(d);
demodulator = new Fsk2Demodulator(this.baud, dsr, pll, false);
decoder = new FlexDecoder(Convert.ToUInt32(this.baud), messageReceived);
}

public override void Process(float[] values, Action<float> writeSample = null)
{
var filtered_values = values;
var filtered_values = interpolator.Process(values);

if (!DISABLE_FILTER)
{
filtered_values = filter.Process(values);
filtered_values = filter.Process(filtered_values);
}

var demodulated = demodulator.Process(filtered_values, writeSample);
var decimated_values = decimator.Process(filtered_values);

var demodulated = demodulator.Process(decimated_values, writeSample);
decoder.Process(demodulated);
}
}
Expand Down
43 changes: 34 additions & 9 deletions SdrsDecoder/Pocsag/PocsagChain.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using SdrsDecoder.Support;
using SdrsDecoder.Support;
using System;

namespace SdrsDecoder.Pocsag
{
Expand All @@ -13,28 +12,54 @@ public class PocsagChain : ChainBase

public bool DISABLE_FILTER = false;

private Interpolator interpolator;
private Decimator decimator;


public PocsagChain(float baud, float sampleRate, Action<MessageBase> messageReceived) : base(sampleRate, messageReceived)
{
this.baud = baud;


var i = 1;
var d = 1;

if (baud == 1200)
{
i = 8;
d = 25;
}

if (baud == 2400)
{
i = 16;
d = 25;
}

var isr = sampleRate * i;
var dsr = isr / d;

//var pll = new PllDecimalPi(sampleRate, baud, PllUpdateType.Both, 0.2M, 0.01M);
var pll = new Pll(sampleRate, baud);
var pll = new Pll(dsr, baud);

filter = new ChebyFilter(this.baud, 1f, sampleRate);
demodulator = new Fsk2Demodulator(this.baud, sampleRate, pll, true);
interpolator = new Interpolator(i);
filter = new ChebyFilter(this.baud, 1f, isr);
decimator = new Decimator(d);
demodulator = new Fsk2Demodulator(this.baud, dsr, pll, true);
decoder = new PocsagDecoder(Convert.ToUInt32(this.baud), messageReceived);
}

public override void Process(float[] values, Action<float> writeSample = null)
{
var filtered_values = values;
var filtered_values = interpolator.Process(values);

if (!DISABLE_FILTER)
{
filtered_values = filter.Process(filtered_values);
}

var demodulated = demodulator.Process(filtered_values, writeSample);
var decimated_values = decimator.Process(filtered_values);

var demodulated = demodulator.Process(decimated_values, writeSample);
decoder.Process(demodulated);
}
}
Expand Down
17 changes: 17 additions & 0 deletions SdrsDecoder/Support/Decimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,44 @@ public Decimator(int value)
this.Value = value;
}

//private float[] overflow;

public float[] Process(float[] values)
{
if (this.Value <= 1)
{
return values;
}

//if (overflow!=null)
//{
// values = overflow.Concat(values).ToArray();
//}

var result = new float[values.Length / this.Value];

//var overflowSet = false;

for (var x = 0; x < result.Length; x++)
{
var p = x * this.Value;

if (p > values.Length - 1)
{
//overflowSet = true;
//overflow = values.Skip((x - 1) * this.Value).ToArray();

continue;
}

result[x] = values[p];
}

//if (!overflowSet)
//{
// overflow = null;
//}

return result;
}

Expand Down
5 changes: 5 additions & 0 deletions SdrsDecoder/Support/Pll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public Pll(float sampleRate, float baud)

public override bool Process(float value, Action<float> writeSample = null)
{
//if (lo_phase < 0)
//{
// lo_phase = 0;
//}

if (lo_phase >= phase_per_sample)
{
lo_phase = 0;
Expand Down

0 comments on commit df10da4

Please sign in to comment.