mirror of https://github.com/EspoTek/Labrador.git
chore + feat : added support for CH2 DFT, and auto-normalization of display, still need to add moving frequency window support
Signed-off-by: Vincenzo Petrolo <vincenzo@kernel-space.org>
This commit is contained in:
parent
bdf01b5ffb
commit
b1b183b613
|
@ -105,13 +105,6 @@ QVector<double> AsyncDFT::getPowerSpectrum(QVector<double> input)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < (n_samples+1)/2; i++) {
|
|
||||||
amplitude[i] /= maximum;
|
|
||||||
amplitude[i] *= 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
maximum = 100;
|
|
||||||
|
|
||||||
return amplitude;
|
return amplitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,3 +131,23 @@ std::unique_ptr<short[]> AsyncDFT::getWindow()
|
||||||
|
|
||||||
return readData;
|
return readData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVector<double> AsyncDFT::normalizeDFT(double e_maximum, QVector<double> dft)
|
||||||
|
{
|
||||||
|
double u_maximum;
|
||||||
|
|
||||||
|
/*Normalize with the greater maximum*/
|
||||||
|
if (this->maximum > e_maximum) {
|
||||||
|
u_maximum = this->maximum;
|
||||||
|
} else {
|
||||||
|
u_maximum = e_maximum;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=0; i < dft.size(); i++) {
|
||||||
|
dft[i] /= u_maximum;
|
||||||
|
dft[i] *= 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dft;
|
||||||
|
}
|
||||||
|
|
|
@ -24,6 +24,9 @@ public:
|
||||||
|
|
||||||
/*Return the window of samples*/
|
/*Return the window of samples*/
|
||||||
std::unique_ptr<short[]> getWindow();
|
std::unique_ptr<short[]> getWindow();
|
||||||
|
|
||||||
|
/*Normalize the DFT*/
|
||||||
|
QVector<double> normalizeDFT(double e_maximum, QVector<double> dft);
|
||||||
private:
|
private:
|
||||||
/*Thread manager method*/
|
/*Thread manager method*/
|
||||||
void threadManager(); //threaded
|
void threadManager(); //threaded
|
||||||
|
|
|
@ -669,24 +669,27 @@ void isoDriver::frameActionGeneric(char CH1_mode, char CH2_mode)
|
||||||
if(CH1_mode == -2) readDataFile = internalBufferFile->readBuffer(display.window,GRAPH_SAMPLES,false, display.delay);
|
if(CH1_mode == -2) readDataFile = internalBufferFile->readBuffer(display.window,GRAPH_SAMPLES,false, display.delay);
|
||||||
|
|
||||||
/*Convert data also for spectrum CH1 and CH2*/
|
/*Convert data also for spectrum CH1 and CH2*/
|
||||||
std::unique_ptr<short[]> dt_samples = internalBuffer375_CH1->async_dft.getWindow();
|
std::unique_ptr<short[]> dt_samples1 = internalBuffer375_CH1->async_dft.getWindow();
|
||||||
|
std::unique_ptr<short[]> dt_samples2 = internalBuffer375_CH2->async_dft.getWindow();
|
||||||
|
|
||||||
|
|
||||||
QVector<double> x(GRAPH_SAMPLES), CH1(GRAPH_SAMPLES), CH2(GRAPH_SAMPLES),
|
QVector<double> x(GRAPH_SAMPLES), CH1(GRAPH_SAMPLES), CH2(GRAPH_SAMPLES),
|
||||||
converted_dt_samples(internalBuffer375_CH1->async_dft.n_samples);
|
converted_dt_samples1(internalBuffer375_CH1->async_dft.n_samples),
|
||||||
|
converted_dt_samples2(internalBuffer375_CH2->async_dft.n_samples);
|
||||||
|
|
||||||
if (CH1_mode == 1){
|
if (CH1_mode == 1){
|
||||||
analogConvert(readData375_CH1.get(), &CH1, 128, AC_CH1, 1);
|
analogConvert(readData375_CH1.get(), &CH1, 128, AC_CH1, 1);
|
||||||
analogConvert(dt_samples.get(), &converted_dt_samples, 128, AC_CH1, 1);
|
analogConvert(dt_samples1.get(), &converted_dt_samples1, 128, AC_CH1, 1);
|
||||||
|
|
||||||
for (int i=0; i < CH1.size(); i++)
|
for (int i=0; i < CH1.size(); i++)
|
||||||
{
|
{
|
||||||
CH1[i] /= m_attenuation_CH1;
|
CH1[i] /= m_attenuation_CH1;
|
||||||
CH1[i] += m_offset_CH1;
|
CH1[i] += m_offset_CH1;
|
||||||
}
|
}
|
||||||
for (int i=0; i < converted_dt_samples.size(); i++)
|
for (int i=0; i < converted_dt_samples1.size(); i++)
|
||||||
{
|
{
|
||||||
converted_dt_samples[i] /= m_attenuation_CH1;
|
converted_dt_samples1[i] /= m_attenuation_CH1;
|
||||||
converted_dt_samples[i] += m_offset_CH1;
|
converted_dt_samples1[i] += m_offset_CH1;
|
||||||
}
|
}
|
||||||
xmin = (currentVmin < xmin) ? currentVmin : xmin;
|
xmin = (currentVmin < xmin) ? currentVmin : xmin;
|
||||||
xmax = (currentVmax > xmax) ? currentVmax : xmax;
|
xmax = (currentVmax > xmax) ? currentVmax : xmax;
|
||||||
|
@ -698,11 +701,18 @@ void isoDriver::frameActionGeneric(char CH1_mode, char CH2_mode)
|
||||||
|
|
||||||
if (CH2_mode == 1){
|
if (CH2_mode == 1){
|
||||||
analogConvert(readData375_CH2.get(), &CH2, 128, AC_CH2, 2);
|
analogConvert(readData375_CH2.get(), &CH2, 128, AC_CH2, 2);
|
||||||
|
analogConvert(dt_samples2.get(), &converted_dt_samples2, 128, AC_CH2, 2);
|
||||||
|
|
||||||
for (int i=0; i < GRAPH_SAMPLES; i++)
|
for (int i=0; i < GRAPH_SAMPLES; i++)
|
||||||
{
|
{
|
||||||
CH2[i] /= m_attenuation_CH2;
|
CH2[i] /= m_attenuation_CH2;
|
||||||
CH2[i] += m_offset_CH2;
|
CH2[i] += m_offset_CH2;
|
||||||
}
|
}
|
||||||
|
for (int i=0; i < converted_dt_samples2.size(); i++)
|
||||||
|
{
|
||||||
|
converted_dt_samples2[i] /= m_attenuation_CH1;
|
||||||
|
converted_dt_samples2[i] += m_offset_CH1;
|
||||||
|
}
|
||||||
ymin = (currentVmin < ymin) ? currentVmin : ymin;
|
ymin = (currentVmin < ymin) ? currentVmin : ymin;
|
||||||
ymax = (currentVmax > ymax) ? currentVmax : ymax;
|
ymax = (currentVmax > ymax) ? currentVmax : ymax;
|
||||||
broadcastStats(1);
|
broadcastStats(1);
|
||||||
|
@ -739,18 +749,29 @@ void isoDriver::frameActionGeneric(char CH1_mode, char CH2_mode)
|
||||||
} else{
|
} else{
|
||||||
if (spectrum) { /*If frequency spectrum mode*/
|
if (spectrum) { /*If frequency spectrum mode*/
|
||||||
try {
|
try {
|
||||||
QVector<double> amplitude = internalBuffer375_CH1->async_dft.getPowerSpectrum(converted_dt_samples);
|
/*Creating DFT amplitudes*/
|
||||||
|
QVector<double> amplitude1 = internalBuffer375_CH1->async_dft.getPowerSpectrum(converted_dt_samples1);
|
||||||
|
/*Getting array of frequencies for display purposes*/
|
||||||
QVector<double> f = internalBuffer375_CH1->async_dft.getFrequenciyWindow(internalBuffer375_CH1->m_samplesPerSecond);
|
QVector<double> f = internalBuffer375_CH1->async_dft.getFrequenciyWindow(internalBuffer375_CH1->m_samplesPerSecond);
|
||||||
double maximum = internalBuffer375_CH1->async_dft.maximum;
|
|
||||||
axes->graph(0)->setData(f,amplitude);
|
/*Max amplitude for display purposes*/
|
||||||
#if 0
|
double max1 = internalBuffer375_CH1->async_dft.maximum;
|
||||||
|
double max2 = -1;
|
||||||
|
|
||||||
if(CH2_mode) {
|
if(CH2_mode) {
|
||||||
amplitude = getDFTAmplitude(CH2);
|
QVector<double> amplitude2 = internalBuffer375_CH2->async_dft.getPowerSpectrum(converted_dt_samples2);
|
||||||
axes->graph(1)->setData(f,amplitude);
|
max2 = internalBuffer375_CH2->async_dft.maximum;
|
||||||
|
/*Normalization with respect to amplitude1*/
|
||||||
|
amplitude2 = internalBuffer375_CH2->async_dft.normalizeDFT(max1, amplitude2);
|
||||||
|
axes->graph(1)->setData(f,amplitude2);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
/*Decision for normalization & display purposes*/
|
||||||
|
amplitude1 = internalBuffer375_CH1->async_dft.normalizeDFT(max2, amplitude1);
|
||||||
|
axes->graph(0)->setData(f,amplitude1);
|
||||||
axes->xAxis->setRange(f.last(), f.front());
|
axes->xAxis->setRange(f.last(), f.front());
|
||||||
axes->yAxis->setRange(maximum,0);
|
/*Setting maximum/minimum y-axis 0%-100%*/
|
||||||
|
axes->yAxis->setRange(100,0);
|
||||||
} catch (std::exception) {
|
} catch (std::exception) {
|
||||||
std::cout << "Cannot yet get correct value for DFT" << std::endl;
|
std::cout << "Cannot yet get correct value for DFT" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue