void c_log(creal_T *x) { real_T x_re; real_T x_im; real_T b_x_im; real_T b_x_re; if ((x->im == 0.0) && rtIsNaN(x->re)) { } else if ((fabs(x->re) > 8.9884656743115785E+307) || (fabs(x->im) > 8.9884656743115785E+307)) { x_re = x->re; x_im = x->im; b_x_im = x->im; b_x_re = x->re; x->re = log(rt_hypotd_snf(fabs(x_re / 2.0), fabs(x_im / 2.0))) + 0.69314718055994529; x->im = rt_atan2d_snf(b_x_im, b_x_re); } else { x_re = x->re; x_im = x->im; b_x_im = x->im; b_x_re = x->re; x->re = log(rt_hypotd_snf(fabs(x_re), fabs(x_im))); x->im = rt_atan2d_snf(b_x_im, b_x_re); } }
/* * Arguments : const creal_T x[513] * double y[513] * Return Type : void */ void b_abs(const creal_T x[513], double y[513]) { int k; for (k = 0; k < 513; k++) { y[k] = rt_hypotd_snf(x[k].re, x[k].im); } }
/* Function Definitions */ void d_abs(const creal_T x_data[65], const int32_T x_size[2], real_T y_data[65], int32_T y_size[2]) { int8_T iv0[2]; int32_T k; for (k = 0; k < 2; k++) { iv0[k] = (int8_T)x_size[k]; } y_size[0] = 1; y_size[1] = iv0[1]; for (k = 0; k <= x_size[1] - 1; k++) { y_data[k] = rt_hypotd_snf(fabs(x_data[k].re), fabs(x_data[k].im)); } }
static void eml_qrsolve(const emxArray_real_T *A, emxArray_real_T *B, emxArray_real_T *Y) { emxArray_real_T *b_A; real_T wj; real_T s; int32_T mn; int32_T nmip1; int32_T itemp; emxArray_real_T *tau; emxArray_int32_T *jpvt; emxArray_real_T *work; int32_T m; int32_T n; int32_T b_mn; emxArray_real_T *vn1; emxArray_real_T *vn2; int32_T k; int32_T ix; int32_T i; int32_T i_i; int32_T nmi; int32_T mmi; real_T rankR; real_T y; boolean_T exitg1; uint32_T unnamed_idx_0; b_emxInit_real_T(&b_A, 2); wj = (real_T)A->size[0]; s = (real_T)A->size[1]; if (wj <= s) { s = wj; } mn = (int32_T)s - 1; nmip1 = b_A->size[0] * b_A->size[1]; b_A->size[0] = A->size[0]; b_A->size[1] = A->size[1]; emxEnsureCapacity((emxArray__common *)b_A, nmip1, (int32_T)sizeof(real_T)); itemp = A->size[0] * A->size[1] - 1; for (nmip1 = 0; nmip1 <= itemp; nmip1++) { b_A->data[nmip1] = A->data[nmip1]; } emxInit_real_T(&tau, 1); emxInit_int32_T(&jpvt, 2); emxInit_real_T(&work, 1); m = A->size[0]; n = A->size[1]; if (m <= n) { b_mn = m; } else { b_mn = n; } nmip1 = tau->size[0]; tau->size[0] = b_mn; emxEnsureCapacity((emxArray__common *)tau, nmip1, (int32_T)sizeof(real_T)); eml_signed_integer_colon(n, jpvt); nmip1 = work->size[0]; work->size[0] = n; emxEnsureCapacity((emxArray__common *)work, nmip1, (int32_T)sizeof(real_T)); itemp = n - 1; for (nmip1 = 0; nmip1 <= itemp; nmip1++) { work->data[nmip1] = 0.0; } emxInit_real_T(&vn1, 1); emxInit_real_T(&vn2, 1); nmip1 = vn1->size[0]; vn1->size[0] = n; emxEnsureCapacity((emxArray__common *)vn1, nmip1, (int32_T)sizeof(real_T)); nmip1 = vn2->size[0]; vn2->size[0] = vn1->size[0]; emxEnsureCapacity((emxArray__common *)vn2, nmip1, (int32_T)sizeof(real_T)); k = 1; for (ix = 0; ix + 1 <= n; ix++) { vn1->data[ix] = eml_xnrm2(m, A, k); vn2->data[ix] = vn1->data[ix]; k += m; } for (i = 0; i + 1 <= b_mn; i++) { i_i = i + i * m; nmi = (n - i) - 1; mmi = (m - i) - 1; nmip1 = 1 + nmi; if (nmip1 < 1) { itemp = -1; } else { itemp = 0; if (nmip1 > 1) { ix = i; wj = fabs(vn1->data[i]); for (k = 2; k <= nmip1; k++) { ix++; s = fabs(vn1->data[ix]); if (s > wj) { itemp = k - 1; wj = s; } } } } nmip1 = i + itemp; if (nmip1 + 1 != i + 1) { eml_xswap(m, b_A, m * nmip1 + 1, 1, m * i + 1, 1); itemp = jpvt->data[nmip1]; jpvt->data[nmip1] = jpvt->data[i]; jpvt->data[i] = itemp; vn1->data[nmip1] = vn1->data[i]; vn2->data[nmip1] = vn2->data[i]; } if (i + 1 < m) { k = i_i + 2; rankR = b_A->data[i_i]; y = 0.0; if (mmi + 1 <= 0) { } else { wj = eml_xnrm2(mmi, b_A, k); if (wj != 0.0) { s = rt_hypotd_snf(fabs(b_A->data[i_i]), wj); if (b_A->data[i_i] >= 0.0) { s = -s; } if (fabs(s) < 1.0020841800044864E-292) { nmip1 = 0; do { nmip1++; eml_xscal(mmi, 9.9792015476736E+291, b_A, k); s *= 9.9792015476736E+291; rankR *= 9.9792015476736E+291; } while (!(fabs(s) >= 1.0020841800044864E-292)); wj = eml_xnrm2(mmi, b_A, k); s = rt_hypotd_snf(fabs(rankR), wj); if (rankR >= 0.0) { s = -s; } y = (s - rankR) / s; eml_xscal(mmi, 1.0 / (rankR - s), b_A, k); for (k = 1; k <= nmip1; k++) { s *= 1.0020841800044864E-292; } rankR = s; } else { y = (s - b_A->data[i_i]) / s; wj = 1.0 / (b_A->data[i_i] - s); eml_xscal(mmi, wj, b_A, k); rankR = s; } } } tau->data[i] = y; } else { wj = b_A->data[i_i]; rankR = b_A->data[i_i]; b_A->data[i_i] = wj; tau->data[i] = 0.0; } b_A->data[i_i] = rankR; if (i + 1 < n) { rankR = b_A->data[i_i]; b_A->data[i_i] = 1.0; eml_matlab_zlarf(mmi + 1, nmi, i_i + 1, tau->data[i], b_A, (i + (i + 1) * m) + 1, m, work); b_A->data[i_i] = rankR; } for (ix = i + 1; ix + 1 <= n; ix++) { if (vn1->data[ix] != 0.0) { s = fabs(b_A->data[i + b_A->size[0] * ix]) / vn1->data[ix]; y = s * s; s = 1.0 - s * s; if (1.0 - y < 0.0) { s = 0.0; } wj = vn1->data[ix] / vn2->data[ix]; if (s * (wj * wj) <= 1.4901161193847656E-8) { if (i + 1 < m) { k = (i + m * ix) + 1; y = 0.0; if (mmi < 1) { } else if (mmi == 1) { y = fabs(b_A->data[k]); } else { wj = 2.2250738585072014E-308; itemp = k + mmi; while (k + 1 <= itemp) { s = fabs(b_A->data[k]); if (s > wj) { rankR = wj / s; y = 1.0 + y * rankR * rankR; wj = s; } else { rankR = s / wj; y += rankR * rankR; } k++; } y = wj * sqrt(y); } vn1->data[ix] = y; vn2->data[ix] = vn1->data[ix]; } else { vn1->data[ix] = 0.0; vn2->data[ix] = 0.0; } } else { vn1->data[ix] *= sqrt(s); } } } } emxFree_real_T(&vn2); emxFree_real_T(&vn1); emxFree_real_T(&work); rankR = 0.0; k = 0; exitg1 = FALSE; while ((exitg1 == 0U) && (k <= mn)) { wj = (real_T)A->size[0]; s = (real_T)A->size[1]; if (wj >= s) { s = wj; } if (fabs(b_A->data[k + b_A->size[0] * k]) <= s * fabs(b_A->data[0]) * 2.2204460492503131E-16) { exitg1 = TRUE; } else { rankR++; k++; } } unnamed_idx_0 = (uint32_T)A->size[1]; nmip1 = Y->size[0]; Y->size[0] = (int32_T)unnamed_idx_0; emxEnsureCapacity((emxArray__common *)Y, nmip1, (int32_T)sizeof(real_T)); itemp = (int32_T)unnamed_idx_0 - 1; for (nmip1 = 0; nmip1 <= itemp; nmip1++) { Y->data[nmip1] = 0.0; } for (ix = 0; ix <= mn; ix++) { if (tau->data[ix] != 0.0) { wj = B->data[ix]; nmip1 = A->size[0] + (int32_T)(1.0 - ((1.0 + (real_T)ix) + 1.0)); for (i = 0; i <= nmip1 - 1; i++) { unnamed_idx_0 = ((uint32_T)ix + (uint32_T)i) + 2U; wj += b_A->data[((int32_T)unnamed_idx_0 + b_A->size[0] * ix) - 1] * B->data[(int32_T)unnamed_idx_0 - 1]; } wj *= tau->data[ix]; if (wj != 0.0) { B->data[ix] -= wj; nmip1 = A->size[0] + (int32_T)(1.0 - ((1.0 + (real_T)ix) + 1.0)); for (i = 0; i <= nmip1 - 1; i++) { unnamed_idx_0 = ((uint32_T)ix + (uint32_T)i) + 2U; B->data[(int32_T)unnamed_idx_0 - 1] -= b_A->data[((int32_T) unnamed_idx_0 + b_A->size[0] * ix) - 1] * wj; } } } } emxFree_real_T(&tau); for (i = 0; i <= (int32_T)rankR - 1; i++) { Y->data[jpvt->data[(int32_T)(1.0 + (real_T)i) - 1] - 1] = B->data[(int32_T) (1.0 + (real_T)i) - 1]; } for (ix = 0; ix <= (int32_T)-(1.0 + (-1.0 - rankR)) - 1; ix++) { wj = rankR + -(real_T)ix; Y->data[jpvt->data[(int32_T)wj - 1] - 1] = eml_div(Y->data[jpvt->data [(int32_T)wj - 1] - 1], b_A->data[((int32_T)wj + b_A->size[0] * ((int32_T) wj - 1)) - 1]); for (i = 0; i <= (int32_T)wj - 2; i++) { Y->data[jpvt->data[(int32_T)(1.0 + (real_T)i) - 1] - 1] -= Y->data [jpvt->data[(int32_T)wj - 1] - 1] * b_A->data[((int32_T)(1.0 + (real_T)i) + b_A->size[0] * ((int32_T)wj - 1)) - 1]; } } emxFree_int32_T(&jpvt); emxFree_real_T(&b_A); }
/* Function Definitions */ void b_sqrt(creal_T *x) { real_T absxi; real_T absxr; if (x->im == 0.0) { if (x->re < 0.0) { absxi = 0.0; absxr = sqrt(fabs(x->re)); } else { absxi = sqrt(x->re); absxr = 0.0; } } else if (x->re == 0.0) { if (x->im < 0.0) { absxi = sqrt(-x->im / 2.0); absxr = -absxi; } else { absxi = sqrt(x->im / 2.0); absxr = absxi; } } else if (rtIsNaN(x->re) || rtIsNaN(x->im)) { absxi = rtNaN; absxr = rtNaN; } else if (rtIsInf(x->im)) { absxi = rtInf; absxr = x->im; } else if (rtIsInf(x->re)) { if (x->re < 0.0) { absxi = 0.0; absxr = rtInf; } else { absxi = rtInf; absxr = 0.0; } } else { absxr = fabs(x->re); absxi = fabs(x->im); if ((absxr > 4.4942328371557893E+307) || (absxi > 4.4942328371557893E+307)) { absxr *= 0.5; absxi *= 0.5; absxi = rt_hypotd_snf(absxr, absxi); if (absxi > absxr) { absxi = sqrt(absxi) * sqrt(1.0 + absxr / absxi); } else { absxi = sqrt(absxi) * 1.4142135623730951; } } else { absxi = sqrt((rt_hypotd_snf(absxr, absxi) + absxr) * 0.5); } if (x->re > 0.0) { absxr = 0.5 * (x->im / absxi); } else { if (x->im < 0.0) { absxr = -absxi; } else { absxr = absxi; } absxi = 0.5 * (x->im / absxr); } } x->re = absxi; x->im = absxr; }
/* * Fs - Sampling frequency * Arguments : double Fs * emxArray_real_T *data * emxArray_real_T *f * emxArray_real_T *YY * Return Type : void */ void spectral(double Fs, emxArray_real_T *data, emxArray_real_T *f, emxArray_real_T *YY) { emxArray_boolean_T *b; int nxin; int k0; int nrowx; int nxout; int k; emxArray_real_T *b_data; int eint; double fdbl; double delta1; emxArray_creal_T *Y; double NFFT; emxArray_creal_T *x; emxInit_boolean_T(&b, 1); nxin = b->size[0]; b->size[0] = data->size[0]; emxEnsureCapacity((emxArray__common *)b, nxin, (int)sizeof(boolean_T)); k0 = data->size[0]; for (nxin = 0; nxin < k0; nxin++) { b->data[nxin] = rtIsNaN(data->data[nxin]); } nxin = data->size[0]; nrowx = data->size[0]; nxout = 0; for (k = 1; k <= b->size[0]; k++) { nxout += b->data[k - 1]; } nxout = data->size[0] - nxout; k0 = -1; for (k = 1; k <= nxin; k++) { if ((k > b->size[0]) || (!b->data[k - 1])) { k0++; data->data[k0] = data->data[k - 1]; } } emxFree_boolean_T(&b); if (nrowx != 1) { if (1 > nxout) { k0 = 0; } else { k0 = nxout; } emxInit_real_T(&b_data, 1); nxin = b_data->size[0]; b_data->size[0] = k0; emxEnsureCapacity((emxArray__common *)b_data, nxin, (int)sizeof(double)); for (nxin = 0; nxin < k0; nxin++) { b_data->data[nxin] = data->data[nxin]; } nxin = data->size[0]; data->size[0] = b_data->size[0]; emxEnsureCapacity((emxArray__common *)data, nxin, (int)sizeof(double)); k0 = b_data->size[0]; for (nxin = 0; nxin < k0; nxin++) { data->data[nxin] = b_data->data[nxin]; } emxFree_real_T(&b_data); } else { nxin = data->size[0]; if (1 > nxout) { data->size[0] = 0; } else { data->size[0] = nxout; } emxEnsureCapacity((emxArray__common *)data, nxin, (int)sizeof(double)); } fdbl = frexp(data->size[0], &eint); delta1 = eint; if (fdbl == 0.5) { delta1 = (double)eint - 1.0; } emxInit_creal_T(&Y, 1); NFFT = rt_powd_snf(2.0, delta1); /* Next power of 2 from length of y */ fft(data, NFFT, Y); nxout = data->size[0]; nxin = Y->size[0]; emxEnsureCapacity((emxArray__common *)Y, nxin, (int)sizeof(creal_T)); k0 = Y->size[0]; for (nxin = 0; nxin < k0; nxin++) { fdbl = Y->data[nxin].re; delta1 = Y->data[nxin].im; if (delta1 == 0.0) { Y->data[nxin].re = fdbl / (double)nxout; Y->data[nxin].im = 0.0; } else if (fdbl == 0.0) { Y->data[nxin].re = 0.0; Y->data[nxin].im = delta1 / (double)nxout; } else { Y->data[nxin].re = fdbl / (double)nxout; Y->data[nxin].im = delta1 / (double)nxout; } } fdbl = Fs / 2.0; nxin = f->size[0] * f->size[1]; f->size[0] = 1; f->size[1] = (int)floor(NFFT / 2.0 + 1.0); emxEnsureCapacity((emxArray__common *)f, nxin, (int)sizeof(double)); f->data[f->size[1] - 1] = 1.0; if (f->size[1] >= 2) { f->data[0] = 0.0; if (f->size[1] >= 3) { delta1 = 1.0 / ((double)f->size[1] - 1.0); nxin = f->size[1]; for (k = 0; k <= nxin - 3; k++) { f->data[1 + k] = (1.0 + (double)k) * delta1; } } } nxin = f->size[0] * f->size[1]; f->size[0] = 1; emxEnsureCapacity((emxArray__common *)f, nxin, (int)sizeof(double)); nxout = f->size[0]; k0 = f->size[1]; k0 *= nxout; for (nxin = 0; nxin < k0; nxin++) { f->data[nxin] *= fdbl; } emxInit_creal_T(&x, 1); fdbl = NFFT / 2.0 + 1.0; k0 = (int)(NFFT / 2.0 + 1.0); nxin = x->size[0]; x->size[0] = k0; emxEnsureCapacity((emxArray__common *)x, nxin, (int)sizeof(creal_T)); for (nxin = 0; nxin < k0; nxin++) { x->data[nxin] = Y->data[nxin]; } emxFree_creal_T(&Y); nxin = YY->size[0]; YY->size[0] = (int)fdbl; emxEnsureCapacity((emxArray__common *)YY, nxin, (int)sizeof(double)); for (k = 0; k + 1 <= (int)fdbl; k++) { YY->data[k] = rt_hypotd_snf(x->data[k].re, x->data[k].im); } emxFree_creal_T(&x); nxin = YY->size[0]; emxEnsureCapacity((emxArray__common *)YY, nxin, (int)sizeof(double)); k0 = YY->size[0]; for (nxin = 0; nxin < k0; nxin++) { YY->data[nxin] *= 2.0; } /* figure; */ /* plot(f,2*abs(Y(1:NFFT/2+1))); */ /* L = length(data); % Length of signal */ /* NFFT = 2^nextpow2(L); */ /* f = Fs/2*linspace(0,1,NFFT/2+1); */ /* figure(1) */ /* Y = fft(data,NFFT)/L; */ /* % Plot single-sided amplitude spectrum. */ /* plot(f,2*abs(Y(1:NFFT/2+1))) % 船首向信号谱分析 */ /* set(gca,'xlim',[0.005 0.5],'ylimmode','auto'); */ /* title('艏向快速傅里叶变换'); */ /* xlabel('频率/Hz'); */ /* ylabel('功率'); */ /* box off */ }