double averageSignalDifference(const SignalSource &first, const SignalSource &second) { auto size = qMin(first.size(), second.size()); double sum; for (int i = 0 ; i < size; i++) { sum += qAbs(first[i] - second[i]); } return sum / size; }
SignalSource makeSignalDifference(const SignalSource &first, const SignalSource &second) { auto size = qMin(first.size(), second.size()); SignalSource result; for (int64_t i = 0 ; i < size; i++) { result.push_back(first[i] - second[i]); } return result; }
/** * Loads sound data from an instance of SignalSource-subclass. * * Data read from source are converted to SFML-compatible sample array * and loaded into the buffer. * * Name capitalized for consistency with SFML coding style. * * @todo get rid of copying data around, let's come up with some better way * * @param source signal source * @return true if successfully loaded */ bool SoundBufferAdapter::loadFromSignalSource(const SignalSource &source) { sf::Int16* samples = new sf::Int16[source.getSamplesCount()]; std::copy(source.begin(), source.end(), samples); bool result = loadFromSamples(samples, source.getSamplesCount(), 1, static_cast<unsigned int>(source.getSampleFrequency())); delete [] samples; return result; }
QVector<double> overThresholdsAmplitudeSum(const SignalSource &signal, double threshold, int neighbourhood) { QVector<double> result; for (auto i = 0; i < signal.size(); i++) { double sum = 0.0; for (auto j = i - neighbourhood; j < i + neighbourhood; j++) { if (j >= 0 && j < signal.size() && qAbs(signal[j]) > threshold) { sum += qAbs(signal[j]) - threshold; } } result << sum; } return result; }
double MSE(const SignalSource &signal1, const SignalSource &signal2) { long double sum = 0; auto size = qMin(signal1.size(), signal2.size()); for (auto i = 0; i < size; i++) { qDebug() << QString("%1 %2").arg(signal1[i]).arg(signal2[i]); auto s1 = gauss(signal1[i]); auto s2 = gauss(signal2[i]); auto g = (s1-s2)*(s1-s2); qDebug() << g; sum += g; } return sum / size; }
void SourceSelectionView::populateSources() { SourceDiscovery* s = SourceDiscovery::Instance(); s->getSources(&signalSources); for(unsigned i=0;i<signalSources.size(); ++i) { SignalSource* src = signalSources[i]; new QListWidgetItem(src->getName(), sourceList); } sourceList->setSelectionMode(QAbstractItemView::SingleSelection); sourceList->setCurrentRow(0); }
void SourceSelectionView::showConfigurationDialog() { SignalSource* selectedSource = signalSources[sourceList->currentRow()]; try { selectedSource->connect(); configView = new SourceConfigView(selectedSource, this); MainWindow::Instance()->pushView(configView); } catch (MException e) { displayException(&e, "Unable to connected to the selected signal source"); } }
/** * Performs the actual frame division. * * Frames are only "pointing" to the original source. There is no copying * of sample data. Each frame can be considered as a standalone fragment * of the source data. * * @param source a reference to source object * @param samplesPerFrame how many samples will each frame hold * @param samplesPerOverlap how many samples are common to adjacent frames */ void FramesCollection::divideFrames(const SignalSource &source, unsigned int samplesPerFrame, unsigned int samplesPerOverlap) { m_samplesPerFrame = samplesPerFrame; const std::size_t sourceSize = source.getSamplesCount(); const unsigned int nonOverlapped = samplesPerFrame - samplesPerOverlap; const unsigned int framesCount = sourceSize / nonOverlapped; m_frames.reserve(framesCount); unsigned int indexBegin = 0, indexEnd = 0; for (std::size_t i = 0; i < framesCount; ++i) { // calculate each frame boundaries // when frame end exceeds source size, break out indexBegin = i * nonOverlapped; indexEnd = indexBegin + samplesPerFrame; if (indexEnd < sourceSize) m_frames.push_back(Frame(source, indexBegin, indexEnd)); else break; } }
/** * Creates the frame object - sets signal source and frame boundaries. * * Frame should not change original data, so the source is a const * reference. * * @param source const reference to signal source * @param indexBegin position of first sample of this frame in the source * @param indexEnd position of last sample of this frame in the source */ Frame::Frame(const SignalSource& source, unsigned int indexBegin, unsigned int indexEnd): m_source(&source), m_begin(indexBegin), m_end((indexEnd > source.getSamplesCount()) ? source.getSamplesCount() : indexEnd) { }