Add option to delay the acquisition by an amount of time (samples)

The first number of samples that "fit" in the given time interval will
be ignored by Pixelpulse2 when displaying the captured buffer (or when
applying different types of mesurements on the buffer).

Signed-off-by: Dan <Dan.Nechita@analog.com>
This commit is contained in:
Dan committed 2016-07-07 20:22:50 +03:00
1 parent 208b080eed
commit 67a1cb481e
8 files changed
+131 -11

No files matched your search

+2 -1
View File
@@ -4,5 +4,6 @@ FloatBuffer::FloatBuffer(QObject *parent):
QObject(parent),
m_secondsPerSample(0.00001),
m_start(0),
m_length(0)
m_length(0),
m_first_samples_ignored(0)
{}
+27 -4
View File
@@ -22,6 +22,16 @@ public:
return m_length;
}
Q_INVOKABLE unsigned long ignoredFirstSamplesCount()
{
return m_first_samples_ignored;
}
Q_INVOKABLE void setIgnoredFirstSamplesCount(unsigned long count)
{
m_first_samples_ignored = count;
}
Q_INVOKABLE float get(unsigned i) {
return m_data[wrapIndex(i)];
}
@@ -111,21 +121,21 @@ public:
double peak_to_peak(){
if(m_data.size() != 0) {
return *std::max_element(m_data.begin(), m_data.end()) - *std::min_element(m_data.begin(), m_data.end());
return *std::max_element(data_begin(), m_data.end()) - *std::min_element(data_begin(), m_data.end());
}
return 0;
}
std::vector<float> dif_mean(double avg){
std::vector<float> tmp;
for (std::vector<float>::iterator it = m_data.begin(); it != m_data.end(); ++it){
for (std::vector<float>::iterator it = data_begin(); it != m_data.end(); ++it){
tmp.push_back(*it - avg);
}
return tmp;
}
double mean() {
return accumulate(m_data.begin(), m_data.end(), 0.0) / m_data.size();
return accumulate(data_begin(), m_data.end(), 0.0) / data_size();
}
signals:
@@ -141,6 +151,7 @@ private:
std::vector<float> m_data;
size_t m_start;
size_t m_length;
size_t m_first_samples_ignored;
unsigned unwrapIndex(unsigned index) {
if (index >= m_start) {
@@ -151,7 +162,7 @@ private:
}
unsigned wrapIndex(unsigned index) {
return (index + m_start) % m_data.size();
return (index + m_start + m_first_samples_ignored) % m_data.size();
}
unsigned timeToIndex(double time) {
@@ -164,4 +175,16 @@ private:
double indexToTime(unsigned index) {
return index * m_secondsPerSample;
}
/* A number of samples at the beginning of the buffer can be ignored by
* the application. Use data_begin() and data_size() to access the rest of data */
std::vector<float>::iterator data_begin()
{
return (m_data.begin() + m_first_samples_ignored);
}
float data_size()
{
return (m_data.size() - m_first_samples_ignored);
}
};
+2 -1
View File
@@ -50,7 +50,8 @@ OTHER_FILES += \
qml/Axes.qml \
qml/OverlayPeriodic.qml \
qml/DragDot.qml \
qml/DeviceRow.qml
qml/DeviceRow.qml \
qml/AcquisitionSettingsDialog.qml
HEADERS += \
SMU.h \
+1
View File
@@ -34,5 +34,6 @@
<file>qml/DeviceManagerPane.qml</file>
<file>qml/ColorControlDialog.qml</file>
<file>qml/StyleSlider.qml</file>
<file>qml/AcquisitionSettingsDialog.qml</file>
</qresource>
</RCC>
+85
View File
@@ -0,0 +1,85 @@
import QtQuick 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls 1.0
import QtQuick.Controls.Styles 1.1
import QtQuick.Dialogs 1.0
import QtQuick.Dialogs 1.2
import QtGraphicalEffects 1.0
Dialog {
title: "Acquisition Settings"
width: 300
height: 200
modality: Qt.NonModal
contentItem:
Rectangle{
id: rectangle
anchors.fill: parent
color: '#222'
RowLayout {
anchors.fill: parent
anchors.topMargin: 40
anchors.bottomMargin: 40
anchors.leftMargin: 40
anchors.rightMargin: 40
spacing: 25
Text {
id: delayLabel
text: "Delay (ms)"
color: 'white'
font.pixelSize: 14
}
SpinBox {
id: delay
maximumValue: 50
minimumValue: 0
decimals: 2
stepSize: 0.01
activeFocusOnPress: true
activeFocusOnTab: true
implicitWidth: 75
// style: SpinBoxStyle {
// background: Rectangle {
// //anchors.fill: parent
// implicitWidth: 100
// implicitHeight: 30
// color: rectangle.color
// }
// textColor: 'white'
// }
onValueChanged: {
var timeInSeconds = delay.value / 1000.0;
var sampleCount = controller.sampleRate * timeInSeconds;
if (sampleCount !== controller.delaySampleCount) {
controller.delaySampleCount = sampleCount;
for (var i = 0; i < session.devices.length; i++) {
for (var j = 0; j < session.devices[i].channels.length; j++) {
session.devices[i].channels[j].signals[0].buffer.setIgnoredFirstSamplesCount(sampleCount);
session.devices[i].channels[j].signals[1].buffer.setIgnoredFirstSamplesCount(sampleCount);
}
}
}
}
Keys.onPressed: {
switch (event.key) {
case Qt.Key_PageDown:
delay.value -= 0.5;
break;
case Qt.Key_PageUp:
delay.value += 0.5;
break;
}
}
}
}
}
}
+2 -1
View File
@@ -8,8 +8,9 @@ Item {
property real sampleRate: session.devices.length ? session.devices[0].DefaultRate : 0
property real maxOutSignalFreq: sampleRate / 5 // A period of a signal should contain at least 5 samples
property real sampleTime: 0.1
readonly property int sampleCount: sampleTime * sampleRate
readonly property int sampleCount: sampleTime * sampleRate + delaySampleCount
property bool restartAfterStop: false
property int delaySampleCount: 0
function trigger() {
session.sampleRate = sampleRate
+3 -3
View File
@@ -6,7 +6,7 @@ Item {
property real sampleTick: 1/controller.sampleRate
property real period: signal.src.period * sampleTick
property real phase: (signal.src.phase % signal.src.period) * sampleTick
property real phase: ((signal.src.phase + controller.delaySampleCount) % signal.src.period) * sampleTick
function phaseZeroNearCenter() {
if (dragging && relX != null) return relX
@@ -75,7 +75,7 @@ Item {
signal.src.period = constrainInterval(newPeriod, 0, controller.sampleRate / controller.maxOutSignalFreq);
signal.src.v1 = overlay.mapY(pos);
// Adjust phase so the signal stays in the same position relative to the other dot
signal.src.phase = -relX/sampleTick;
signal.src.phase = -relX/sampleTick - controller.delaySampleCount;
}
}
@@ -97,7 +97,7 @@ Item {
if (pos.modifiers & Qt.ControlModifier) {
signal.src.phase = axes.snapx(-relX/sampleTick)
} else {
signal.src.phase = -relX/sampleTick
signal.src.phase = -relX/sampleTick - controller.delaySampleCount;
}
signal.src.v2 = overlay.mapY(pos)
}
+9 -1
View File
@@ -19,6 +19,10 @@ ToolbarStyle {
property alias deviceMngrVisible: deviceMngrVisibleItem.checked
property alias colorDialog: sessColorDialog
AcquisitionSettingsDialog {
id: sessAcqSettDialog
}
FileDialog {
id: dataDialog
selectExisting: false
@@ -90,6 +94,11 @@ ToolbarStyle {
}
MenuSeparator{}
MenuItem {
id: acquisVisibleItem
text: "Acqusition Settings"
onTriggered: sessAcqSettDialog.visible = true
}
MenuItem {
id: dataSaveVisibleItem
text: "Export Data"
@@ -131,4 +140,3 @@ ToolbarStyle {
}
}
}