Revision 02e339cc

b/host/examples/tx_waveforms.cpp
17 17

  
18 18
#include <uhd/utils/thread_priority.hpp>
19 19
#include <uhd/utils/safe_main.hpp>
20
#include <uhd/utils/static.hpp>
20 21
#include <uhd/usrp/simple_usrp.hpp>
21 22
#include <boost/program_options.hpp>
22 23
#include <boost/thread/thread_time.hpp> //system time
......
44 45
    return std::fmod(x, 1)*2 - 1;
45 46
}
46 47

  
48
#define sine_table_len 2048
49
static float sine_table[sine_table_len];
50
UHD_STATIC_BLOCK(gen_sine_table){
51
    static const float m_pi = std::acos(float(-1));
52
    for (size_t i = 0; i < sine_table_len; i++)
53
        sine_table[i] = std::sin((2*m_pi*i)/sine_table_len);
54
}
55

  
47 56
float gen_sine(float x){
48
    static const float two_pi = 2*std::acos(float(-1));
49
    return std::sin(x*two_pi);
57
    return sine_table[size_t(x*sine_table_len)%sine_table_len];
50 58
}
51 59

  
52 60
int UHD_SAFE_MAIN(int argc, char *argv[]){
......
65 73
        ("args", po::value<std::string>(&args)->default_value(""), "simple uhd device address args")
66 74
        ("duration", po::value<size_t>(&total_duration)->default_value(3), "number of seconds to transmit")
67 75
        ("spb", po::value<size_t>(&spb)->default_value(10000), "samples per buffer")
68
        ("rate", po::value<double>(&rate)->default_value(100e6/16), "rate of outgoing samples")
76
        ("rate", po::value<double>(&rate)->default_value(1.5e6), "rate of outgoing samples")
69 77
        ("freq", po::value<double>(&freq)->default_value(0), "rf center frequency in Hz")
70 78
        ("ampl", po::value<float>(&ampl)->default_value(float(0.3)), "amplitude of the waveform")
71 79
        ("gain", po::value<float>(&gain)->default_value(float(0)), "gain for the RF chain")
72
        ("wave-type", po::value<std::string>(&wave_type)->default_value("SINE"), "waveform type (CONST, SQUARE, RAMP, SINE)")
80
        ("wave-type", po::value<std::string>(&wave_type)->default_value("CONST"), "waveform type (CONST, SQUARE, RAMP, SINE)")
73 81
        ("wave-freq", po::value<double>(&wave_freq)->default_value(0), "waveform frequency in Hz")
74 82
    ;
75 83
    po::variables_map vm;
......
113 121
    if (std::abs(wave_freq) > sdev->get_tx_rate()/2){
114 122
        throw std::runtime_error("wave freq out of Nyquist zone");
115 123
    }
124
    if (sdev->get_tx_rate()/std::abs(wave_freq) > sine_table_len/2 and wave_type == "SINE"){
125
        throw std::runtime_error("sine freq too small for table");
126
    }
116 127

  
117 128
    //store the generator function for the selected waveform
118 129
    boost::function<float(float)> wave_gen;

Also available in: Unified diff