codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include "stdio.h" #include "math.h" int main(void) { int32_t Np = 4093; int32_t amp_int = 8192; int32_t TL = 16385; int32_t last_idx=0; int32_t double_sample_value; int32_t lsb_sample_value; int32_t msb_sample_value; int32_t i; int32_t coeffs[16384]; double Ts = (double) Np / TL; for(i=TL-1;i>=0;i--){ double tm = fmod(2*M_PI*Ts*i, 2*M_PI); double tm_1 = fmod(2*M_PI*Ts*(i-1), 2*M_PI); double delta = tm - tm_1; if(abs(delta)>M_PI){ last_idx = i-1; break; } } double c_ph = 2*M_PI - fmod(2*M_PI*Ts*last_idx, 2*M_PI) - 2*M_PI*Ts/2; double amp = 1.0; for(int i=1;i<TL;i++) { //1 double c = cos(fmod(2*M_PI*Ts*(last_idx+i+1), 2*M_PI) + c_ph); int16_t c_fx = (int16_t)floor(amp_int*c)+8192; coeffs[i-1] = c_fx; } // Loading waveform for (i=0; i<8192; i++){//8192 lsb_sample_value = (coeffs[i*2] & 0xffff); //0xe000 ^ msb_sample_value = (coeffs[i*2+1] & 0xffff); //0xe000 ^ double_sample_value = (msb_sample_value << 16 ) | lsb_sample_value; coeffs[i] =double_sample_value; if(i<128){ std::cout << std::hex << lsb_sample_value << std::endl; std::cout << std::hex << msb_sample_value << std::endl; } } // ----------------------------------------------------------------- // Done with the load. Release the force return 0; }
Private
[
?
]
Run code
Submit