Ejemplo n.º 1
0
static double filterToneGetRMS(
    const double sampRate,
    const double waveFreq,
    const size_t decim,
    const size_t interp
)
{
    auto env = Pothos::ProxyEnvironment::make("managed");
    auto registry = env->findProxy("Pothos/BlockRegistry");

    auto waveSource = registry.callProxy("/blocks/waveform_source", "complex128");
    waveSource.callVoid("setWaveform", "SINE");
    waveSource.callVoid("setFrequency", waveFreq);
    waveSource.callVoid("setSampleRate", sampRate);

    auto finiteRelease = registry.callProxy("/blocks/finite_release");
    finiteRelease.callVoid("setTotalElements", 4096);

    auto filter = registry.callProxy("/blocks/fir_filter", "complex128", "COMPLEX");
    filter.callVoid("setDecimation", decim);
    filter.callVoid("setInterpolation", interp);

    auto designer = registry.callProxy("/blocks/fir_designer");
    designer.callVoid("setSampleRate", (sampRate*interp)/decim);
    designer.callVoid("setFilterType", "COMPLEX_BAND_PASS");
    designer.callVoid("setFrequencyLower", waveFreq-0.1*sampRate);
    designer.callVoid("setFrequencyUpper", waveFreq+0.1*sampRate);
    designer.callVoid("setNumTaps", 100);

    auto probe = registry.callProxy("/blocks/stream_probe", "complex128");
    probe.callVoid("setMode", "RMS");

    //propagate the taps
    {
        Pothos::Topology topology;
        topology.connect(designer, "tapsChanged", filter, "setTaps");
        topology.commit();
        POTHOS_TEST_TRUE(topology.waitInactive());
    }

    //run the topology
    {
        Pothos::Topology topology;
        topology.connect(waveSource, 0, finiteRelease, 0);
        topology.connect(finiteRelease, 0, filter, 0);
        topology.connect(filter, 0, probe, 0);
        topology.commit();
        POTHOS_TEST_TRUE(topology.waitInactive());
    }

    return probe.call<double>("value");
}
Ejemplo n.º 2
0
void testBufferConvertComplexComponents(const size_t inVlen, const size_t outVlen)
{
    const size_t numElems = 100 + (std::rand() % 100);
    Pothos::BufferChunk b0(Pothos::DType(typeid(InType), inVlen), numElems);
    const auto primElems = b0.length/b0.dtype.elemSize();

    //random fill primitive elements
    for (size_t i = 0; i < primElems; i++) randType(b0.as<InType *>()[i]);

    //convert
    const auto b1 = b0.convertComplex(Pothos::DType(typeid(OutType), outVlen), numElems);

    //check
    std::cout << "testBufferConvertComplexComponents: " << b0.dtype.toString() << " to " << b1.first.dtype.toString() << "...\t" << std::flush;
    for (size_t i = 0; i < primElems; i++)
    {
        const auto in = b0.as<const InType *>()[i];
        const auto outRe = b1.first.as<const OutType *>()[i];
        const auto outIm = b1.second.as<const OutType *>()[i];
        if (not checkEqual(in.real(), outRe) or not checkEqual(in.imag(), outIm))
        {
            std::cerr << "elem " << i << ": " << in << " != " << outRe << ", " << outIm << std::endl;
            POTHOS_TEST_TRUE(checkEqual(in.real(), outRe) and checkEqual(in.imag(), outIm));
        }
    }
    std::cout << "OK" << std::endl;
}
Ejemplo n.º 3
0
static void delayBlockTestCase(const int delayVal)
{
    auto feeder = Pothos::BlockRegistry::make("/blocks/feeder_source", "int");
    auto delay = Pothos::BlockRegistry::make("/blocks/delay");
    auto collector = Pothos::BlockRegistry::make("/blocks/collector_sink", "int");

    //setup
    std::cout << "delayBlockTestCase " << delayVal << std::endl;
    Pothos::BufferChunk buff0(typeid(int), 100);
    feeder.callVoid("feedBuffer", buff0);
    delay.callVoid("setDelay", delayVal);

    //run the topology
    std::cout << "run the topology\n";
    {
        Pothos::Topology topology;
        topology.connect(feeder, 0, delay, 0);
        topology.connect(delay, 0, collector, 0);
        topology.commit();
        POTHOS_TEST_TRUE(topology.waitInactive());
    }

    auto buff1 = collector.call<Pothos::BufferChunk>("getBuffer");
    POTHOS_TEST_EQUAL(buff1.elements(), size_t(100-delayVal));
}
void testComparatorTmpl(const double val, const std::string op_string)
{
    auto dtype = Pothos::DType(typeid(Type));
    std::cout << "Testing comparator with type " << dtype.toString() << ", value " << val << std::endl;

    auto feeder0 = Pothos::BlockRegistry::make("/blocks/feeder_source", dtype);
    auto feeder1 = Pothos::BlockRegistry::make("/blocks/feeder_source", dtype);
    auto comp = Pothos::BlockRegistry::make("/comms/comparator", dtype, op_string);
    auto collector = Pothos::BlockRegistry::make("/blocks/collector_sink", "char");

    //load the feeder
    auto buffIn0 = Pothos::BufferChunk(typeid(Type), NUM_POINTS);
    auto pIn0 = buffIn0.as<Type *>();
    auto buffIn1 = Pothos::BufferChunk(typeid(Type), NUM_POINTS);
    auto pIn1 = buffIn1.as<Type *>();

    for (size_t i = 0; i < buffIn0.elements(); i++)
    {
        pIn0[i] = Type(i);
        pIn1[i] = Type(val);
    }
    
    feeder0.callProxy("feedBuffer", buffIn0);
    feeder1.callProxy("feedBuffer", buffIn1);

    //run the topology
    {
        Pothos::Topology topology;
        topology.connect(feeder0, 0, comp, 0);
        topology.connect(feeder1, 0, comp, 1);
        topology.connect(comp, 0, collector, 0);
        topology.commit();
        POTHOS_TEST_TRUE(topology.waitInactive(0.01));
    }

    //check the collector
    auto buffOut = collector.call<Pothos::BufferChunk>("getBuffer");
    POTHOS_TEST_EQUAL(buffOut.length, NUM_POINTS*sizeof(char));
    auto pOut = buffOut.as<const char *>();
    for (size_t i = 0; i < NUM_POINTS; i++)
    {
      char expected;
      if (op_string == ">")
        expected = (pIn0[i] > pIn1[i]);
      else if (op_string == "<")
        expected = (pIn0[i] < pIn1[i]);
      else if (op_string == "<=")
        expected = (pIn0[i] <= pIn1[i]);
      else if (op_string == ">=")
        expected = (pIn0[i] >= pIn1[i]);
      else if (op_string == "==")
        expected = (pIn0[i] == pIn1[i]);
      else if (op_string == "!=")
        expected = (pIn0[i] != pIn1[i]);
      POTHOS_TEST_EQUAL(pOut[i], expected);
    }
}