123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- //
- // 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: RadarSignalGenerator301.cpp
- //
- // MATLAB Coder version : 5.3
- // C/C++ source code generated on : 27-Apr-2023 00:24:12
- //
- // Include Files
- #include "RadarSignalGenerator301.h"
- #include "AbstractLinearFMWaveform301.h"
- #include "LinearFMWaveform301.h"
- #include "../rt_nonfinite.h"
- #include "../coder_array.h"
- #include <cmath>
- // Function Declarations
- static void times(coder::array<creal_T, 1U> &xt,
- const coder::array<creal_T, 1U> &r);
- // Function Definitions
- //
- // Arguments : coder::array<creal_T, 1U> &xt
- // const coder::array<creal_T, 1U> &r
- // Return Type : void
- //
- static void times(coder::array<creal_T, 1U> &xt,
- const coder::array<creal_T, 1U> &r)
- {
- coder::array<creal_T, 1U> 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<double, 1U> &sig
- // double *fs
- // double PRF[3]
- // double *len
- // Return Type : void
- //
- void RadarSignalGenerator301(coder::array<double, 1U> &sig, double *fs,
- double PRF[3], double *len)
- {
- coder::phased::LinearFMWaveform301 wavGen;
- coder::array<creal_T, 1U> r;
- coder::array<creal_T, 1U> r1;
- coder::array<creal_T, 1U> r3;
- coder::array<creal_T, 1U> xt;
- coder::array<double, 2U> r2;
- coder::array<double, 1U> b_xt;
- double idx;
- 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<int>(std::fmod(static_cast<double>(ii) + 1.0, 3.0));
- if (mode == 0) {
- mode = 3;
- }
- *len += 2.0E+10 / PRF[mode - 1];
- }
- ndbl = static_cast<int>(*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<int>(std::fmod(static_cast<double>(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<int>(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;
- }
- coder::phased::AbstractLinearFMWaveform301::getMatchingWaveform(r);
- for (k = 0; k < 20000; k++) {
- xt[k] = r[k];
- }
- coder::phased::AbstractLinearFMWaveform301::getMatchingWaveform(r1);
- // 载波调制
- kd = (static_cast<double>(xt.size(0)) - 1.0) / 2.0E+10;
- ndbl = static_cast<int>(std::floor(kd / 5.0E-11 + 0.5));
- OutputPulseIndex_idx_0 = static_cast<double>(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<double>(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<double>(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<double>(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<int>(idx) - 2;
- nm1d2 = static_cast<int>(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 RadarSignalGenerator301.cpp
- //
- // [EOF]
- //
|