// // Academic License - for use in teaching, academic research, and meeting // course requirements at degree granting institutions only. Not for // government, commercial, or other organizational use. // File: RadarSignalGenerator101.cpp // // MATLAB Coder version : 5.3 // C/C++ source code generated on : 26-Apr-2023 23:32:52 // // Include Files #include "RadarSignalGenerator101.h" #include "RectangularWaveform101.h" #include "../rt_nonfinite.h" #include "../coder_array.h" #include #include // Function Declarations static void times(coder::array &xt, const coder::array &r); // Function Definitions // // Arguments : coder::array &xt // const coder::array &r // Return Type : void // static void times(coder::array &xt, const coder::array &r) { coder::array b_xt; int i; int loop_ub; int stride_0_0; int stride_1_0; if (r.size(0) == 1) { i = xt.size(0); } else { i = r.size(0); } b_xt.set_size(i); stride_0_0 = (xt.size(0) != 1); stride_1_0 = (r.size(0) != 1); if (r.size(0) == 1) { loop_ub = xt.size(0); } else { loop_ub = r.size(0); } for (i = 0; i < loop_ub; i++) { double d; double d1; int i1; i1 = i * stride_1_0; d = r[i1].im; d1 = r[i1].re; b_xt[i].re = xt[i * stride_0_0].re * d1 - xt[i * stride_0_0].im * d; b_xt[i].im = xt[i * stride_0_0].re * d + xt[i * stride_0_0].im * d1; } xt.set_size(b_xt.size(0)); loop_ub = b_xt.size(0); for (i = 0; i < loop_ub; i++) { xt[i] = b_xt[i]; } } // // RADARSIGNALGENERATOR1 此处显示有关此函数的摘要 // 此处显示详细说明 // // Arguments : coder::array &sig // double *fs // double PRF[3] // double *len // Return Type : void // void RadarSignalGenerator101(coder::array &sig, double *fs, double PRF[3], double *len) { coder::phased::RectangularWaveform101 wavGen; coder::array b_x; coder::array r; coder::array r1; coder::array r3; coder::array x; coder::array xt; coder::array r2; coder::array b_xt; double idx; int b_exponent; int exponent; int ii; int k; int mode; int ndbl; PRF[0] = 500000.0; PRF[1] = 333333.33333333331; PRF[2] = 250000.0; // simTime = 2e-5; // 方波定义 wavGen.isInitialized = 0; wavGen.matlabCodegenIsDeleted = false; // 线性调频波定义 // 产生5个脉冲 // numPulses = fix(simTime*PRF); *len = 0.0; for (ii = 0; ii < 5; ii++) { mode = static_cast(std::fmod(static_cast(ii) + 1.0, 3.0)); if (mode == 0) { mode = 3; } *len += 2.0E+10 / PRF[mode - 1]; } ndbl = static_cast(*len); sig.set_size(ndbl); for (k = 0; k < ndbl; k++) { sig[k] = 0.0; } idx = 1.0; for (ii = 0; ii < 5; ii++) { double OutputPulseIndex_idx_0; double cdiff; double kd; int nm1d2; mode = static_cast(std::fmod(static_cast(ii) + 1.0, 3.0)); if (mode == 0) { mode = 3; } // 迭代波形 if (wavGen.isInitialized != 1) { wavGen.isInitialized = 1; wavGen.isSetupComplete = true; wavGen.pOutputStartPulseIndex = 1.0; wavGen.pOutputPulseInterval[0] = 0.0; wavGen.pOutputPulseInterval[1] = 1.0; } kd = (wavGen.pOutputStartPulseIndex + wavGen.pOutputPulseInterval[0]) - 1.0; if (std::isnan(kd) || std::isinf(kd)) { cdiff = rtNaN; } else if (kd == 0.0) { cdiff = 0.0; } else { cdiff = std::fmod(kd, 3.0); if (cdiff == 0.0) { cdiff = 0.0; } else if (kd < 0.0) { cdiff += 3.0; } } OutputPulseIndex_idx_0 = cdiff + 1.0; kd = (wavGen.pOutputStartPulseIndex + wavGen.pOutputPulseInterval[1]) - 1.0; if (std::isnan(kd) || std::isinf(kd)) { cdiff = rtNaN; } else if (kd == 0.0) { cdiff = 0.0; } else { cdiff = std::fmod(kd, 3.0); if (cdiff == 0.0) { cdiff = 0.0; } else if (kd < 0.0) { cdiff += 3.0; } } wavGen.pOutputStartPulseIndex = cdiff + 1.0; ndbl = 20000 * (static_cast(OutputPulseIndex_idx_0) - 1); xt.set_size(ndbl + 40000); for (k = 0; k <= ndbl + 39999; k++) { xt[k].re = 0.0; xt[k].im = 0.0; } frexp(20000.0, &exponent); x.set_size(20000); for (k = 0; k < 20000; k++) { x[k].re = 0.0; x[k].im = 0.0; x[k].re = 1.0; x[k].im = 0.0; } r.set_size(20000); for (k = 0; k < 20000; k++) { r[k] = x[k]; } for (k = 0; k < 20000; k++) { xt[k] = r[k]; } frexp(20000.0, &b_exponent); b_x.set_size(20000); for (k = 0; k < 20000; k++) { b_x[k].re = 0.0; b_x[k].im = 0.0; b_x[k].re = 1.0; b_x[k].im = 0.0; } r1.set_size(20000); for (k = 0; k < 20000; k++) { r1[k] = b_x[k]; } // 载波调制 kd = (static_cast(xt.size(0)) - 1.0) / 2.0E+10; ndbl = static_cast(std::floor(kd / 5.0E-11 + 0.5)); OutputPulseIndex_idx_0 = static_cast(ndbl) * 5.0E-11; cdiff = OutputPulseIndex_idx_0 - kd; if (std::abs(cdiff) < 4.4408920985006262E-16 * std::abs(kd)) { ndbl++; OutputPulseIndex_idx_0 = kd; } else if (cdiff > 0.0) { OutputPulseIndex_idx_0 = (static_cast(ndbl) - 1.0) * 5.0E-11; } else { ndbl++; } r2.set_size(1, ndbl); r2[0] = 0.0; r2[ndbl - 1] = OutputPulseIndex_idx_0; nm1d2 = (ndbl - 1) / 2; for (k = 0; k <= nm1d2 - 2; k++) { kd = (static_cast(k) + 1.0) * 5.0E-11; r2[k + 1] = kd; r2[(ndbl - k) - 2] = OutputPulseIndex_idx_0 - kd; } if (nm1d2 << 1 == ndbl - 1) { r2[nm1d2] = OutputPulseIndex_idx_0 / 2.0; } else { kd = static_cast(nm1d2) * 5.0E-11; r2[nm1d2] = kd; r2[nm1d2 + 1] = OutputPulseIndex_idx_0 - kd; } r3.set_size(r2.size(1)); ndbl = r2.size(1); for (k = 0; k < ndbl; k++) { r3[k].re = r2[k] * 0.0; r3[k].im = r2[k] * 5.969026041820607E+10; } ndbl = r3.size(0); for (k = 0; k < ndbl; k++) { if (r3[k].im == 0.0) { r3[k].re = std::exp(r3[k].re); r3[k].im = 0.0; } else if (std::isinf(r3[k].im) && std::isinf(r3[k].re) && (r3[k].re < 0.0)) { r3[k].re = 0.0; r3[k].im = 0.0; } else { cdiff = std::exp(r3[k].re / 2.0); r3[k].re = cdiff * (cdiff * std::cos(r3[k].im)); r3[k].im = cdiff * (cdiff * std::sin(r3[k].im)); } } if (xt.size(0) == r3.size(0)) { ndbl = xt.size(0); for (k = 0; k < ndbl; k++) { double re_tmp; kd = xt[k].re; OutputPulseIndex_idx_0 = r3[k].im; cdiff = xt[k].im; re_tmp = r3[k].re; xt[k].re = kd * re_tmp - cdiff * OutputPulseIndex_idx_0; xt[k].im = kd * OutputPulseIndex_idx_0 + cdiff * re_tmp; } } else { times(xt, r3); } kd = idx + 2.0E+10 / PRF[mode - 1]; if (idx > kd - 1.0) { k = -1; nm1d2 = 0; } else { k = static_cast(idx) - 2; nm1d2 = static_cast(kd - 1.0); } b_xt.set_size(xt.size(0)); ndbl = xt.size(0); for (mode = 0; mode < ndbl; mode++) { b_xt[mode] = xt[mode].re; } ndbl = (nm1d2 - k) - 1; for (nm1d2 = 0; nm1d2 < ndbl; nm1d2++) { sig[(k + nm1d2) + 1] = b_xt[nm1d2]; } idx = kd; } wavGen.matlabCodegenDestructor(); *fs = 2.0E+10; } // // File trailer for RadarSignalGenerator101.cpp // // [EOF] //