Skip to content

Commit b9bf105

Browse files
committed
Support for 10.5k signals
1 parent 4a40fa8 commit b9bf105

18 files changed

Lines changed: 1531 additions & 79 deletions

JAERO/DSP.cpp

Lines changed: 174 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
#include "DSP.h"
5-
#include <assert.h>
65
#include <QDebug>
76

87
//---------------------------------------------------------------------------
@@ -32,6 +31,7 @@ TrigLookUp::TrigLookUp()
3231

3332
WaveTable::WaveTable()
3433
{
34+
last_WTptr=0;
3535
samplerate=48000;
3636
freq=1000;
3737
WTstep=(1000.0)*WTSIZE/(48000);//default
@@ -41,6 +41,7 @@ WaveTable::WaveTable()
4141

4242
WaveTable::WaveTable(int _freq,int _samplerate)
4343
{
44+
last_WTptr=0;
4445
freq=_freq;
4546
samplerate=_samplerate;
4647
if(freq<0)freq=0;
@@ -68,8 +69,9 @@ double WaveTable::DistancebetweenWT(double WTptr1, double WTptr2)
6869

6970
void WaveTable::WTnextFrame()
7071
{
71-
assert(WTptr>=0.0);
72+
JASSERT(WTptr>=0.0);
7273
if(WTstep<0)WTstep=0;
74+
last_WTptr=WTptr;
7375
WTptr+=WTstep;
7476
while(((int)WTptr)>=WTSIZE) WTptr-=WTSIZE;
7577
}
@@ -165,7 +167,7 @@ void WaveTable::IncresePhaseDeg(double phase_deg)
165167
void WaveTable::SetPhaseDeg(double phase_deg)
166168
{
167169
phase_deg=std::fmod(phase_deg,360.0);
168-
if(phase_deg<0)phase_deg+=360.0;
170+
while(phase_deg<0)phase_deg+=360.0;
169171
WTptr=(phase_deg/360.0)*((double)WTSIZE);
170172
}
171173

@@ -199,6 +201,25 @@ bool WaveTable::IfPassesPointNextTime(double FractionOfWave)
199201
return false;
200202
}
201203

204+
bool WaveTable::IfHavePassedPoint(double FractionOfWave)
205+
{
206+
double t_last_WTptr=last_WTptr;
207+
double t_WTptr=WTptr;
208+
double pt=(FractionOfWave*WTSIZE);
209+
t_last_WTptr-=pt;
210+
t_WTptr-=pt;
211+
if(t_last_WTptr<0.0)t_last_WTptr+=WTSIZE;
212+
if(t_WTptr<0.0)t_WTptr+=WTSIZE;
213+
if((t_last_WTptr>WTSIZE_3_4)&&(t_WTptr<WTSIZE_1_4))
214+
{
215+
//FractionOfSampleItPassesBy=(WTstep-t_WTptr)/WTstep;
216+
FractionOfSampleItPassesBy=t_WTptr/WTstep;//WTSIZE;
217+
return true;
218+
}
219+
return false;
220+
}
221+
222+
202223
bool WaveTable::IfPassesPointNextTime_frames(double NumberOfFrames)
203224
{
204225
FractionOfSampleItPassesBy=NumberOfFrames-WTptr;
@@ -211,6 +232,10 @@ bool WaveTable::IfPassesPointNextTime_frames(double NumberOfFrames)
211232
return false;
212233
}
213234

235+
236+
237+
238+
214239
void WaveTable::SetWTptr(double FractionOfWave,double PlusNumberOfFrames)
215240
{
216241
while(FractionOfWave>=1)FractionOfWave-=1;
@@ -304,8 +329,8 @@ double FIR::FIRUpdateAndProcess(double sig, double FractionOfSampleOffset)
304329

305330
void FIR::FIRSetPoint(int point, double value)
306331
{
307-
assert(point>=0);
308-
assert(point<NumberOfPoints);
332+
JASSERT(point>=0);
333+
JASSERT(point<NumberOfPoints);
309334
if((point<0)||(point>=NumberOfPoints))return;
310335
points[point]=value;
311336
}
@@ -314,7 +339,7 @@ void FIR::FIRSetPoint(int point, double value)
314339
AGC::AGC(double _SecondsToAveOver,double _Fs)
315340
{
316341
AGCMASz=round(_SecondsToAveOver*_Fs);
317-
assert(AGCMASz>0);
342+
JASSERT(AGCMASz>0);
318343
AGCMASum=0;
319344
AGCMABuffer=new double[AGCMASz];
320345
for(int i=0;i<AGCMASz;i++)AGCMABuffer[i]=0;
@@ -343,7 +368,7 @@ AGC::~AGC()
343368
MovingAverage::MovingAverage(int number)
344369
{
345370
MASz=round(number);
346-
assert(MASz>0);
371+
JASSERT(MASz>0);
347372
MASum=0;
348373
MABuffer=new double[MASz];
349374
for(int i=0;i<MASz;i++)MABuffer[i]=0;
@@ -361,13 +386,47 @@ double MovingAverage::Update(double sig)
361386
return Val;
362387
}
363388

389+
double MovingAverage::UpdateSigned(double sig)
390+
{
391+
MASum=MASum-MABuffer[MAPtr];
392+
MASum=MASum+(sig);
393+
MABuffer[MAPtr]=(sig);
394+
MAPtr++;MAPtr%=MASz;
395+
Val=MASum/((double)MASz);
396+
return Val;
397+
}
398+
364399
MovingAverage::~MovingAverage()
365400
{
366401
if(MASz)delete [] MABuffer;
367402
}
368403
//---------------------
369404

405+
MSEcalc::MSEcalc(int number)
406+
{
407+
pointmean = new MovingAverage(number);
408+
msema = new MovingAverage(number);
409+
}
410+
MSEcalc::~MSEcalc()
411+
{
412+
delete pointmean;
413+
delete msema;
414+
}
415+
double MSEcalc::Update(cpx_type pt_qpsk)
416+
{
417+
double tda,tdb;
418+
cpx_type tcpx;
419+
pointmean->Update(std::abs(pt_qpsk));
420+
double mu=pointmean->Val;
421+
if(mu<0.000001)mu=0.000001;
422+
tcpx=sqrt(2)*pt_qpsk/mu;
423+
tda=(fabs(tcpx.real())-1.0);
424+
tdb=(fabs(tcpx.imag())-1.0);
425+
mse=msema->Update((tda*tda)+(tdb*tdb));
426+
return mse;
427+
}
370428

429+
//---------------------
371430
MovingVar::MovingVar(int number)
372431
{
373432
E = new MovingAverage(number);
@@ -498,3 +557,111 @@ void BaceConverter::Reset()
498557
ErasurePtr=0;
499558
}
500559

560+
//-----
561+
562+
IIR::IIR()
563+
{
564+
a.resize(3);
565+
b.resize(3);
566+
b[0]=0.00032714218939589035;
567+
b[1]=0;
568+
b[2]=0.00032714218939589035;
569+
a[0]=1;
570+
a[1]=-0.39005299948210803;
571+
a[2]= 0.99934571562120822;
572+
init();
573+
}
574+
575+
void IIR::init()
576+
{
577+
JASSERT(a.size()>=1);
578+
JASSERT(b.size()>=1);
579+
buff_x.resize(b.size());
580+
buff_y.resize(a.size()-1);
581+
buff_x_ptr=0;
582+
buff_y_ptr=0;
583+
buff_x.fill(0);
584+
buff_y.fill(0);
585+
}
586+
587+
double IIR::update(double sig)
588+
{
589+
590+
buff_x.resize(b.size());
591+
buff_y.resize(a.size()-1);
592+
if(buff_x_ptr>=buff_x.size())buff_x_ptr=0;
593+
if(buff_y_ptr>=buff_y.size())buff_y_ptr=0;
594+
595+
ASSERTCH(buff_x,buff_x_ptr);
596+
buff_x[buff_x_ptr]=sig;
597+
buff_x_ptr++;buff_x_ptr%=buff_x.size();
598+
599+
double y=0;
600+
601+
//int tp=buff_x_ptr;
602+
603+
for(int i=b.size()-1;i>=0;i--)
604+
{
605+
ASSERTCH(buff_x,buff_x_ptr);
606+
ASSERTCH(b,i);
607+
y+=buff_x[buff_x_ptr]*b[i];
608+
buff_x_ptr++;buff_x_ptr%=buff_x.size();
609+
}
610+
611+
for(int i=a.size()-1;i>=1;i--)
612+
{
613+
ASSERTCH(buff_y,buff_y_ptr);
614+
ASSERTCH(a,i);
615+
y-=buff_y[buff_y_ptr]*a[i];
616+
buff_y_ptr++;buff_y_ptr%=buff_y.size();
617+
}
618+
619+
ASSERTCH(a,0);
620+
y/=a[0];
621+
622+
ASSERTCH(buff_y,buff_y_ptr);
623+
buff_y[buff_y_ptr]=y;
624+
buff_y_ptr++;buff_y_ptr%=buff_y.size();
625+
626+
return y;
627+
628+
629+
/* a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)
630+
- a(2)*y(n-1) - ... - a(na+1)*y(n-na)*/
631+
}
632+
633+
//----------------
634+
635+
//for alpha==1
636+
//not sure if correct for any other Fs other than 48000 and fb 10500
637+
OQPSKEbNoMeasure::OQPSKEbNoMeasure(int number,double _Fs,double _fb)
638+
{
639+
Fs=_Fs;
640+
fb=_fb;
641+
E = new MovingAverage(number);
642+
E2 = new MovingAverage(number);
643+
}
644+
645+
double OQPSKEbNoMeasure::Update(double sig)
646+
{
647+
E2->Update(sig*sig);
648+
Mean=E->Update(sig);
649+
double MeanSquared=Mean*Mean;
650+
Var=(E2->Val)-(E->Val*E->Val);
651+
Var-=(0.024709*MeanSquared);//remove non constant of OQPSK after RRC
652+
double mvr=(((Fs*MeanSquared/(2.0*fb*Var)))*0.13743);//calibrated using matlab
653+
if(mvr<0.000000001)mvr=0.000000001;
654+
double tebno=10.0*log10(mvr);
655+
if(std::isnan(tebno))tebno=50;
656+
if(tebno>50.0)tebno=50;
657+
if(tebno<0.0)tebno=0;//no real reason but there is no way that less will be usful
658+
EbNo=EbNo*0.8+0.2*tebno;
659+
return EbNo;
660+
}
661+
662+
OQPSKEbNoMeasure::~OQPSKEbNoMeasure()
663+
{
664+
delete E;
665+
delete E2;
666+
}
667+

0 commit comments

Comments
 (0)