fun6.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. //
  2. // File: fun6.cpp
  3. //
  4. // MATLAB Coder version : 5.2
  5. // C/C++ source code generated on : 04-Mar-2023 17:31:12
  6. //
  7. // Include Files
  8. #include "fun6.h"
  9. #include "coder_array.h"
  10. #include <cmath>
  11. #include <iostream>
  12. using namespace std;
  13. // Function Definitions
  14. //
  15. // Arguments : const coder::array<double, 1U> &pulse_sig
  16. // int tgt_idx
  17. // double fs
  18. // double forward_time_length
  19. // double forward_times
  20. // coder::array<double, 2U> &rxsig_noise
  21. // Return Type : void
  22. //
  23. void Slice_forward_interference(const coder::array<double, 1U> &pulse_sig, int tgt_idx, double fs,
  24. double forward_time_length, double forward_times,
  25. coder::array<double, 2U> &rxsig_noise)
  26. {
  27. coder::array<double, 2U> pulse_sig_noise_t;
  28. coder::array<double, 2U> varargin_2;
  29. coder::array<double, 1U> y;
  30. coder::array<unsigned int, 2U> r;
  31. coder::array<boolean_T, 1U> x;
  32. double idx1;
  33. double unnamed_idx_0;
  34. unsigned int idx_data;
  35. int ii_data;
  36. int ii_size;
  37. int k;
  38. int ntilerows;
  39. int nx;
  40. if (pulse_sig.size(0) > 100) {
  41. boolean_T exitg1;
  42. nx = pulse_sig.size(0);
  43. y.set_size(pulse_sig.size(0));
  44. for (k = 0; k < nx; k++) {
  45. y[k] = std::abs(pulse_sig[k]);
  46. }
  47. x.set_size(y.size(0));
  48. nx = y.size(0);
  49. for (k = 0; k < nx; k++) {
  50. x[k] = (y[k] > 0.0);
  51. }
  52. nx = 0;
  53. ii_size = 1;
  54. ntilerows = 0;
  55. exitg1 = false;
  56. while ((!exitg1) && (ntilerows <= x.size(0) - 1)) {
  57. if (x[ntilerows]) {
  58. nx = 1;
  59. ii_data = ntilerows + 1;
  60. exitg1 = true;
  61. } else {
  62. ntilerows++;
  63. }
  64. }
  65. if (nx == 0) {
  66. ii_size = 0;
  67. }
  68. for (k = 0; k < ii_size; k++) {
  69. idx_data = static_cast<unsigned int>(ii_data);
  70. }
  71. }
  72. idx1 = static_cast<double>(idx_data) + std::round(fs * 5.0E-7);
  73. unnamed_idx_0 = std::round(fs * forward_time_length);
  74. r.set_size(1, static_cast<int>(unnamed_idx_0) + 1);
  75. nx = static_cast<int>(unnamed_idx_0);
  76. for (k = 0; k <= nx; k++) {
  77. r[k] = static_cast<unsigned int>(idx1 + static_cast<double>(k));
  78. }
  79. unnamed_idx_0 = idx1 + static_cast<double>(r.size(1));
  80. varargin_2.set_size(r.size(1) * static_cast<int>(forward_times), 1);
  81. nx = r.size(1);
  82. ntilerows = static_cast<int>(forward_times);
  83. for (ii_size = 0; ii_size < ntilerows; ii_size++) {
  84. ii_data = ii_size * nx;
  85. for (k = 0; k < nx; k++) {
  86. varargin_2[ii_data + k] = pulse_sig[static_cast<int>(r[k]) - 1];
  87. }
  88. }
  89. if (static_cast<int>(unnamed_idx_0) != 0) {
  90. ntilerows = static_cast<int>(unnamed_idx_0);
  91. } else {
  92. ntilerows = 0;
  93. }
  94. if (varargin_2.size(0) != 0) {
  95. nx = varargin_2.size(0);
  96. } else {
  97. nx = 0;
  98. }
  99. pulse_sig_noise_t.set_size(ntilerows + nx, 1);
  100. for (k = 0; k < ntilerows; k++) {
  101. pulse_sig_noise_t[k] = 0.0;
  102. }
  103. for (k = 0; k < nx; k++) {
  104. pulse_sig_noise_t[k + ntilerows] = varargin_2[k];
  105. }
  106. if (static_cast<double>(r.size(1)) * forward_times + idx1 >=
  107. pulse_sig.size(0)) {
  108. nx = pulse_sig.size(0);
  109. rxsig_noise.set_size(1, pulse_sig.size(0));
  110. for (k = 0; k < nx; k++) {
  111. rxsig_noise[rxsig_noise.size(0) * k] = pulse_sig_noise_t[k];
  112. }
  113. } else {
  114. nx = pulse_sig_noise_t.size(0);
  115. if (nx <= 1) {
  116. nx = 1;
  117. }
  118. if (pulse_sig_noise_t.size(0) == 0) {
  119. nx = 0;
  120. }
  121. if (pulse_sig.size(0) > nx) {
  122. nx = pulse_sig_noise_t.size(0);
  123. if (nx <= 1) {
  124. nx = 1;
  125. }
  126. if (pulse_sig_noise_t.size(0) == 0) {
  127. nx = 0;
  128. }
  129. nx = pulse_sig.size(0) - nx;
  130. } else {
  131. nx = 0;
  132. }
  133. if (pulse_sig_noise_t.size(0) != 0) {
  134. ntilerows = pulse_sig_noise_t.size(0);
  135. } else {
  136. ntilerows = 0;
  137. }
  138. if (nx == 0) {
  139. nx = 0;
  140. }
  141. rxsig_noise.set_size(ntilerows + nx, 1);
  142. for (k = 0; k < ntilerows; k++) {
  143. rxsig_noise[k] = pulse_sig_noise_t[k];
  144. }
  145. for (k = 0; k < nx; k++) {
  146. rxsig_noise[k + ntilerows] = 0.0;
  147. }
  148. }
  149. }
  150. static coder::array<double, 1U> argInit_Unboundedx1_real_T()
  151. {
  152. coder::array<double, 1U> result;
  153. // Set the size of the array.
  154. // Change this size to the value that the application requires.
  155. result.set_size(200);
  156. // Loop over the array to initialize each element.
  157. for (int idx0{0}; idx0 < result.size(0); idx0++) {
  158. // Set the value of the array element.
  159. // Change this value to the value that the application requires.
  160. result[idx0] = 2;
  161. }
  162. return result;
  163. }
  164. //int main()
  165. //{
  166. // coder::array<double, 2U> rxsig_noise;
  167. // coder::array<double, 1U> pulse_sig;
  168. // // Initialize function 'fun6' input arguments.
  169. // // Initialize function input argument 'pulse_sig'.
  170. // pulse_sig = argInit_Unboundedx1_real_T();
  171. // int tgt_idx = 1;
  172. // double fs = 10e6;
  173. // double forward_time_length = 2e-6;
  174. // double forward_times = 4;
  175. // // Call the entry-point 'fun6'.
  176. // Slice_forward_interference(pulse_sig, tgt_idx, fs, forward_time_length, forward_times, rxsig_noise);
  177. // cout << "rxsig_noise=" <<endl;
  178. // for (int i = 0; i < rxsig_noise.size(0); i++) {
  179. // std::cout << rxsig_noise[i] << " ";
  180. // }
  181. // return 0;
  182. //}