123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- //
- // File: false_speed.cpp
- //
- // MATLAB Coder version : 5.2
- // C/C++ source code generated on : 02-Mar-2023 09:38:59
- //
- // Include Files
- #include "fun2.h"
- #include "colon.h"
- #include "rt_nonfinite.h"
- #include "coder_array.h"
- #include <cmath>
- #include <iostream>
- using namespace std;
- // Function Definitions
- //
- // Arguments : double fd
- // double fo
- // double ts
- // double tau
- // double Tr
- // double k
- // double t_r
- // double V
- // double N
- // coder::array<double, 2U> &S
- // Return Type : void
- //
- void false_speed(double, double fo, double ts, double tau, double Tr, double k,
- double t_r, double V, double N, coder::array<double, 2U> &S)
- {
- coder::array<double, 2U> b_b;
- coder::array<signed char, 2U> Signal_Radar;
- coder::array<signed char, 2U> rect;
- double a;
- double b;
- double b_a;
- int ncols;
- int ntilecols;
-
- // fo = 1e6;
- // ts = 1 / 2e7;
- // tau = 3e-6;
- // Tr = 5e-4;
- // k = 5e6 / 30e-6;
- // t_r = 60e3 / 3e8;
- // V = 600;
- // N = 1;
- b = Tr - ts;
- if (std::isnan(ts) || std::isnan(b)) {
- S.set_size(1, 1);
- S[0] = rtNaN;
- } else if ((ts == 0.0) || ((0.0 < b) && (ts < 0.0)) ||
- ((b < 0.0) && (ts > 0.0))) {
- S.set_size(1, 0);
- } else if (std::isinf(b) && (std::isinf(ts) || (0.0 == b))) {
- S.set_size(1, 1);
- S[0] = rtNaN;
- } else if (std::isinf(ts)) {
- S.set_size(1, 1);
- S[0] = 0.0;
- } else if (std::floor(ts) == ts) {
- ncols = static_cast<int>(std::floor(b / ts));
- S.set_size(1, ncols + 1);
- for (ntilecols = 0; ntilecols <= ncols; ntilecols++) {
- S[ntilecols] = ts * static_cast<double>(ntilecols);
- }
- } else {
- coder::eml_float_colon(ts, b, S);
- }
- // 以ts为间隔产生Tr/ts个抽样
- rect.set_size(1, S.size(1));
- ncols = S.size(1);
- for (ntilecols = 0; ntilecols < ncols; ntilecols++) {
- rect[ntilecols] = 0;
- }
- ntilecols = S.size(1);
- for (ncols = 0; ncols < ntilecols; ncols++) {
- b = S[ncols];
- if ((b >= t_r) && (b <= tau + t_r)) {
- rect[ncols] = 1;
- }
- }
- b = N * Tr - ts;
- if (std::isnan(ts) || std::isnan(b)) {
- S.set_size(1, 1);
- S[0] = rtNaN;
- } else if ((ts == 0.0) || ((0.0 < b) && (ts < 0.0)) ||
- ((b < 0.0) && (ts > 0.0))) {
- S.set_size(S.size(0), 0);
- } else if (std::isinf(b) && (std::isinf(ts) || (0.0 == b))) {
- S.set_size(1, 1);
- S[0] = rtNaN;
- } else if (std::isinf(ts)) {
- S.set_size(1, 1);
- S[0] = 0.0;
- } else if (std::floor(ts) == ts) {
- ncols = static_cast<int>(std::floor(b / ts));
- S.set_size(1, ncols + 1);
- for (ntilecols = 0; ntilecols <= ncols; ntilecols++) {
- S[ntilecols] = ts * static_cast<double>(ntilecols);
- }
- } else {
- coder::eml_float_colon(ts, b, S);
- }
- // 以ts为间隔产生N个脉冲信号的抽样间隔
- Signal_Radar.set_size(1, rect.size(1) * static_cast<int>(N));
- ncols = rect.size(1);
- ntilecols = static_cast<int>(N);
- for (int jtilecol{0}; jtilecol < ntilecols; jtilecol++) {
- int ibtile;
- ibtile = jtilecol * ncols;
- for (int jcol{0}; jcol < ncols; jcol++) {
- Signal_Radar[ibtile + jcol] = rect[jcol];
- }
- }
- // 目标回波信号,重复N个脉冲串
- a = 6.2831853071795862 * (fo + 2.0 * V * fo / 3.0E+8);
- S.set_size(1, S.size(1));
- ncols = S.size(1) - 1;
- for (ntilecols = 0; ntilecols <= ncols; ntilecols++) {
- S[ntilecols] = S[ntilecols] - t_r;
- }
- b_a = 3.1415926535897931 * k;
- b_b.set_size(1, S.size(1));
- ncols = S.size(1);
- for (ntilecols = 0; ntilecols < ncols; ntilecols++) {
- b = S[ntilecols];
- b_b[ntilecols] = b * b;
- }
- S.set_size(1, S.size(1));
- ncols = S.size(1) - 1;
- for (ntilecols = 0; ntilecols <= ncols; ntilecols++) {
- S[ntilecols] = a * S[ntilecols] + b_a * b_b[ntilecols];
- }
- ncols = S.size(1);
- for (ntilecols = 0; ntilecols < ncols; ntilecols++) {
- S[ntilecols] = std::cos(S[ntilecols]);
- }
- S.set_size(1, Signal_Radar.size(1));
- ncols = Signal_Radar.size(1) - 1;
- for (ntilecols = 0; ntilecols <= ncols; ntilecols++) {
- S[ntilecols] = static_cast<double>(Signal_Radar[ntilecols]) * S[ntilecols];
- // printf("%f ", S[ntilecols]);
- }
- }
- //int main()
- //{
- //
- // double fd = 4;
- // double fo = 1e6;
- // double ts = 1e-7;
- // double tau = 30e-6;
- // double Tr = 5e-4;
- // double k = 5e6/30e-6;
- // double t_r = 20e-5;
- // double V = 600;
- // double N = 1;
- // coder::array<double, 2U> S;
- //// coder::array<double, 2U> S_output;
- //
- // false_speed(fd, fo, ts, tau, Tr, k, t_r, V, N, S);
- //
- // // 输出结果
- // for (int i = 0; i < S.size(1); i++) {
- // std::cout << S[i] << " ";
- // }
- // std::cout << std::endl;
- // return 0;
- //}
- //
|