summaryrefslogtreecommitdiff
path: root/gr-digital/lib/modulate_vector.cc
blob: 6ba96f1b58b4ac102058069c34b4c81f37809c60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * Copyright 2015 Free Software Foundation, Inc.
 *
 * This file is part of GNU Radio
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 *
 */

/*
* Generate a modulated transmit vector corresponding to a particular
* data sequence, resampling rate, and shaping filter. The output is
* suitable for use as a candidate filter for the corr_est block, or
* just for prototyping.
*
* It accepts a sptr to a modulator block as an argument; given
* suitable data vectors and arguments you should be able to use any of
* the GNU Radio modulator blocks as a modulator. Be careful that some
* modulators expect packed words, some expect unpacked words, and some
* have unique expectations, requirements, or limitations.

* modulator as: gr.block or gr.hier_block
* taps as: list or array
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gnuradio/blocks/vector_sink.h>
#include <gnuradio/blocks/vector_source.h>
#include <gnuradio/digital/modulate_vector.h>
#include <gnuradio/filter/fir_filter_blk.h>
#include <gnuradio/top_block.h>

namespace gr {
namespace digital {
std::vector<gr_complex> modulate_vector_bc(basic_block_sptr modulator,
                                           std::vector<uint8_t> data,
                                           std::vector<float> taps)
{
    blocks::vector_source_b::sptr vector_src = blocks::vector_source_b::make(data);
    filter::fir_filter_ccf::sptr filter = filter::fir_filter_ccf::make(1, taps);
    blocks::vector_sink_c::sptr vector_sink = blocks::vector_sink_c::make();

    top_block_sptr tb = make_top_block("modulate_vector");

    tb->connect(vector_src, 0, modulator, 0);
    tb->connect(modulator, 0, filter, 0);
    tb->connect(filter, 0, vector_sink, 0);

    tb->run();

    return vector_sink->data();
}
} /* namespace digital */
} /* namespace gr */