TEST(core_signal_test, empty_slot_is_not_same_as_no_slot) { Signal signal; signal.connect(); ASSERT_EQ(1u, signal.size()); signal.connect(Signal::Slot()); ASSERT_EQ(2u, signal.size()); }
TEST(core_signal_test, clear_erases_all_slots) { Signal signal; signal.connect([](int) {}); signal.connect([](int) {}); ASSERT_EQ(2u, signal.size()); signal.clear(); ASSERT_EQ(0u, signal.size()); }
Contour<float> DioF0Estimator::estimate(const Signal &signal, double msFramePeriod) { int decimationRatio = qMax(1, qMin(12, (int)(signal.samplingFrequency() / decimatedFs))); int decimatedLength = 1 + signal.size() / decimationRatio; fft = new Fft(Fft::suitableLength(decimatedLength), Fft::Real); Spectrum decimatedSpectrum(createDecimatedSpectrum(signal, decimationRatio)); Contour<float> result(estimate(decimatedSpectrum, signal.size(), signal.samplingFrequency(), msFramePeriod)); delete fft; return result; }
// receiver: decode received bits. Ns samples per bit. Bits BluetoothReceiver::receive(const Signal& input) { // Input length should be a multiple of Ns int nBits = input.size()/Ns; _ASSERTE((input.size()) % Ns == 0); Bits bitsOut(nBits); for (int i=0; i<nBits; ++i) { slice sl_i(i*Ns, Ns); bitsOut[i] = receiveBit(input[sl_i]); } return bitsOut; }
void Downsampler::revert(Signal& signal) const { // Resize and set the sample rate on the signal int revertedSize = _fineStructure.size(); signal.resize(revertedSize); signal.sampleRate = _fineStructure.sampleRate; // Move the values to their new positions and add the fine structure double sizeRatio = signal.size() / revertedSize; for(int i = revertedSize - 1; i >= 0; i--) signal[i] = signal[sizeRatio * i] + _fineStructure[i]; }
TEST(core_signal_test, executing_signal_actually_works_for_all_of_them) { Signal signal; int a = 0, b = 0; signal.connect([&a](int _i) { a = _i; }); signal.connect([&b](int _i) { b = _i + 1; }); signal(5); ASSERT_EQ(2u, signal.size()); ASSERT_EQ(5, a); ASSERT_EQ(6, b); }
// receiveBit: decode one bit of received data bool BluetoothReceiver::receiveBit(const Signal& inputSlice) { // Check input: Ns samples per bit _ASSERTE(inputSlice.size() == Ns); double phase = 0.0; // Integrate over phase difference for (int i=0; i<Ns; ++i) { Sample bpOut = bandpassFilter.FilterStep(inputSlice[i]); Sample diffOut = differentiatorFilter.FilterStep(bpOut); phase += limiterDiscriminator(bpOut, diffOut); } return (phase < 0.0); }
TransformeeFourier::Signal TransformeeFourier::inverse(const Signal & signal){ Signal returnRecompoTransfoFourier; double N = signal.size(); returnRecompoTransfoFourier.resize((int)(N)); for(double j = -N/2; j < N/2; j++){ returnRecompoTransfoFourier[(j+(N/2))] = 0; for(double i = 0; i < N; i ++){ std::complex<double> c(0.0, ((j+(N/2)))*i*M_PI*2.0/N); returnRecompoTransfoFourier[(j+(N/2))] += signal[i] * exp(c); } } return returnRecompoTransfoFourier; }
void TransformeeFourier::fourier(const Signal & contour){ Signal returnTransfoFourier; double N = contour.size(); tabComplex.resize((int)(N)); for(double j = -N/2; j < N/2; j++){ tabComplex[(j+(N/2))] = 0; for(double i = 0; i < N; i ++){ std::complex<double> c(0.0, ((j+(N/2)))*i*M_PI*2.0/N); tabComplex[(j+(N/2))] += contour[i] * exp(-c); } tabComplex[(j+(N/2))] /= N; } }
DioF0Estimator::Spectrum DioF0Estimator::createDecimatedSpectrum(const Signal &signal, int decimationRatio) { int decimatedLength = 1 + signal.size() / decimationRatio; int fftLength = fft->fftLength; double *decimatedWave = new double[fftLength]; Decimator::decimate(signal, decimationRatio, decimatedWave, decimatedLength); double mean = 0.0; for(int i = 0; i < decimatedLength; i++) { mean += decimatedWave[i]; } mean /= decimatedLength; for(int i = 0; i < decimatedLength; i++) { decimatedWave[i] -= mean; } for(int i = decimatedLength; i < fftLength; i++) { decimatedWave[i] = 0.0; } fft->execute(Fft::Forward, decimatedWave); return Spectrum(decimatedWave, decimatedLength, fftLength, (double)signal.samplingFrequency() / decimationRatio); }
Downsampler::Downsampler(Signal& signal, double targetRate): _fineStructure(signal), _newSampleRate(signal.sampleRate / pow(2, (int)(log(signal.sampleRate / targetRate) / log(2)))) { int oldSize = signal.size(); // Apply a lowpass filter to obtain the fine structure LowpassFilter filter(_newSampleRate / 2); filter.filter(signal); for(int i = 0; i < oldSize; i++) _fineStructure[i] -= signal[i]; // Fill values into new positions int newSize = (int)(_newSampleRate / signal.sampleRate * oldSize); double sizeRatio = oldSize / newSize; for(int i = 0; i < newSize; i++) signal[i] = signal[(int)(sizeRatio * i)]; // Set the new size and sample rate signal.resize(std::min(newSize, oldSize)); signal.sampleRate = _newSampleRate; }