diff --git a/Detector.cpp b/Detector.cpp index fe078a880..8faf99354 100644 --- a/Detector.cpp +++ b/Detector.cpp @@ -7,7 +7,7 @@ #include "moc_Detector.cpp" extern "C" { - void fil4_(qint16*, qint32*, qint16*, qint32*); + void fil4_(qint16*, qint32*, qint16*, qint32*, qint32*); } Detector::Detector (unsigned frameRate, unsigned periodLengthInSeconds, @@ -85,8 +85,10 @@ qint64 Detector::writeData (char const * data, qint64 maxSize) qint32 framesAfterDownSample (m_samplesPerFFT); if(framesToProcess==13824 and dec_data.params.kin>=0 and dec_data.params.kin < (NTMAX*12000 - framesAfterDownSample)) { + int nrefspec=0; + if(g_bRefSpec) nrefspec=1; fil4_(&m_buffer[0], &framesToProcess, &dec_data.d2[dec_data.params.kin], - &framesAfterDownSample); + &framesAfterDownSample, &nrefspec); dec_data.params.kin += framesAfterDownSample; } else { // qDebug() << "framesToProcess = " << framesToProcess; diff --git a/Detector.hpp b/Detector.hpp index 9855be9a2..a8daa0285 100644 --- a/Detector.hpp +++ b/Detector.hpp @@ -1,10 +1,10 @@ #ifndef DETECTOR_HPP__ #define DETECTOR_HPP__ - #include "AudioDevice.hpp" - #include +extern bool g_bRefSpec; + // // output device that distributes data in predefined chunks via a signal // diff --git a/lib/fil4.f90 b/lib/fil4.f90 index 4946da2fe..2a72b397e 100644 --- a/lib/fil4.f90 +++ b/lib/fil4.f90 @@ -1,4 +1,4 @@ -subroutine fil4(id1,n1,id2,n2) +subroutine fil4(id1,n1,id2,n2,nrefspec) ! FIR lowpass filter designed using ScopeFIR @@ -12,10 +12,15 @@ subroutine fil4(id1,n1,id2,n2) parameter (NTAPS=49) parameter (NDOWN=4) !Downsample ratio + parameter (NFFT=13824,NH=NFFT/2) integer*2 id1(n1) integer*2 id2(*) real t(NTAPS) - data t/NTAPS*0.0/ + real x(NFFT) + real s(0:NH) + complex cx(0:NH) + equivalence(x,cx) + data t/NTAPS*0.0/,nrefspec0/-999/ ! Filter coefficients: real w(NTAPS) @@ -33,7 +38,13 @@ subroutine fil4(id1,n1,id2,n2) -0.013752163325,-0.011720748164,-0.005202883094, 0.002613872664, & 0.008706594219, 0.011363155076, 0.010161983649, 0.010051920210, & 0.000861074040/ - save w,t + save w,t,nsave,s,nrefspec0 + + if(nrefspec.ne.nrefspec0) then + s=0. + nsave=0 + nrefspec0=nrefspec + endif n2=n1/NDOWN if(n2*NDOWN.ne.n1) stop 'Error in fil4' @@ -45,5 +56,34 @@ subroutine fil4(id1,n1,id2,n2) id2(i)=nint(dot_product(w,t)) enddo + if(nrefspec.eq.1) then + nsave=nsave+1 + x=0.001*id1 + call four2a(x,NFFT,1,-1,0) !r2c FFT + + do i=1,NH + s(i)=s(i) + real(cx(i))**2 + aimag(cx(i))**2 + enddo + + if(mod(nsave,34).eq.0) then !About 9.8 sec + df=48000.0/NFFT + ia=nint(500.0/df) + ib=nint(2500.0/df) + call pctile(s(ia),ib-ia+1,50,xmed) + db0=db(xmed) + nhadd=10 + open(16,file='refspec.dat',status='unknown') + do i=1,NH + freq=i*df + ia=max(1,i-nhadd) + ib=min(NH,i+nhadd) + smo=sum(s(ia:ib))/(ib-ia+1) + write(16,1000) freq,db(smo)-db0 +1000 format(2f10.3) + enddo + close(16) + endif + endif + return end subroutine fil4 diff --git a/mainwindow.cpp b/mainwindow.cpp index 05e60eb48..48d1c7e7e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -118,6 +118,7 @@ int fast_jh2; int narg[15]; QVector g_ColorTbl; bool g_single_decode; +bool g_bRefSpec; namespace { @@ -676,6 +677,7 @@ MainWindow::MainWindow(bool multiple, QSettings * settings, QSharedMemory *shdme } VHF_features_enabled(m_config.enable_VHF_features()); g_single_decode=m_config.single_decode(); + g_bRefSpec=false; progressBar->setMaximum(m_TRperiod); m_modulator->setPeriod(m_TRperiod); // TODO - not thread safe @@ -1472,7 +1474,11 @@ void MainWindow::closeEvent(QCloseEvent * e) void MainWindow::on_stopButton_clicked() //stopButton { monitor (false); - m_loopall=false; + m_loopall=false; + if(g_bRefSpec) { +// msgBox("Reference spectrum saved."); + g_bRefSpec=false; + } } void MainWindow::msgBox(QString t) //msgBox @@ -5336,7 +5342,7 @@ void MainWindow::fastPick(int x0, int x1, int y) void MainWindow::on_actionSave_reference_spectrum_triggered() { - msgBox("Reference spectrum not presently implemented"); + g_bRefSpec=true; } void MainWindow::on_sbCQRxFreq_valueChanged(int n) diff --git a/mainwindow.ui b/mainwindow.ui index c456045e9..07dc1a3ee 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -2810,7 +2810,7 @@ QPushButton[state="ok"] { - Save reference spectrum + Measure reference spectrum