上一主题下一主题
关键字
主题 : 利用c++频谱仪控件制作,有没有好人帮忙啊
级别: 北风助理工程师

UID: 474136
精华: 0
发帖: 418
威望: 898 点
学点: 715 点
贡献: 0 点
好评: 0 点
学币: 0 个
注册时间: 2014-07-13
最后登录: 2014-12-05
楼主  发表于: 2014-07-28 16:19||

利用c++频谱仪控件制作,有没有好人帮忙啊

大学软件设计实验题目,有没有好人帮忙啊 \0l>q  ,  
YJg,B\z}  
要求:输入给定信号(数组),基于FFT快速频谱计算,给出频谱图显示。并****成控件方便调用。 n+@F`]K e  
格式:设计题目     7!,YNy%  
任务要求     tWTKgbj (  
实验设备及软件     O%g $9-?F0  
参考文献
此帖悬赏结束
最佳答案: 1 学点
最佳答案获得者: 慕容紫英
级别: 北风资深工程师


UID: 472421
精华: 0
发帖: 1405
威望: 1631 点
学点: 64 点
贡献: 23 点
好评: 0 点
学币: 95 个
注册时间: 2014-07-09
最后登录: 2018-07-09
沙发(1楼)  发表于: 2014-07-28 16:21||

先搜索下载安装OpenCV ;RC{<wBTx  
然后参考C:\Program Files\OpenCV\modules\objdetect\src\fft.cpp L\xk:j1[  
C/C++ code KyYMfC  
Mb|a+,:>3  
C.Kh [V\Ut  
#include "precomp.hpp" 6z#acE1)M  
#include "_lsvm_fft.h" /'l{E  
NV72  
int getEntireRes(int number, int divisor, int *entire, int *res) Oj3.q#)`Z  
{ i@)i$i4  
    *entire = number / divisor; e.7EU  
    *res = number % divisor; \IV1j)I"u  
    return FFT_OK; QkEvw<  
} ' g=  
)U7t  
int getMultipliers(int n, int *n1, int *n2) :8=ikwQ  
{ pfA|I*`XV  
    int multiplier, i; |ef7bKU8  
    if (n == 1) f_jo+z{-ik  
    { &:9c AIe]H  
        *n1 = 1; O`x;,6Vr  
        *n2 = 1; WM7oM~&{6  
        return FFT_ERROR; // n = 1 A&.WH?p  
    } U@_dm/;0&  
    multiplier = n / 2; sJ;g$TB  
    for (i = multiplier; i >= 2; i--) ); !eow  
    { `#F{Waww'  
        if (n % i == 0) wSzv|\ G  
        { TJ_$vI  
            *n1 = i;  fHE <(  
            *n2 = n / i; ?26I,:;  
            return FFT_OK; // n = n1 * n2 q0i(i.h  
        } :q$.,EZ4#n  
    } b#uL?f  
    *n1 = 1; 8'r2D+Vwm  
    *n2 = n; tvkb~  
    return FFT_ERROR; // n - prime number / ;$#d}R  
} +X#vVD3"  
^=BTz9QM  
/* 9Tg IB  
// 1-dimensional FFT b*;Si7-  
// <{dVKf,e  
// API |'.*K]Yp  
// int fft(float *x_in, float *x_out, int n, int shift); T%.8 '9  
// INPUT qW$<U3u}  
// x_in              - input signal dT`D:)*:  
// n                 - number of elements for searching Fourier image 3C ?f(J}  
// shift             - shift between input elements X> 1,!I9  
// OUTPUT ?zeJ#i  
// x_out             - output signal (contains 2n elements in order v/Py"hQ  
                       Re(x_in[0]), Im(x_in[0]), Re(x_in[1]), Im(x_in[1]) and etc.) &R[ M c-2  
// RESULT .\[`B.Q  
// Error status |*oZ _gI  
*/ r;B8i!gD  
int fft(float *x_in, float *x_out, int n, int shift) X>d"]GD  
{ $:cE ^8K  
    int n1, n2, res, k1, k2, m1, m2, index, idx; hU(umL<  
    float alpha, beta, gamma, angle, cosAngle, sinAngle; {v=T [D  
    float tmpGamma, tmpAlpha, tmpBeta; %@wJ`F2a_  
    float tmpRe, tmpIm, phaseRe, phaseIm; hXfQ)$J  
    res = getMultipliers(n, &n1, &n2); s:OFVlC%\  
    if (res == FFT_OK) '[U8}z3  
    { >7wOoK|1'  
        fft(x_in, x_out, n1, shift); ;Yx)tWQI  
        fft(x_in, x_out, n2, shift); | h`0u'#  
    } u}>#Eb  
    alpha = (float)(2.0 * PI / ((float)n));  V_C-P[2~  
    beta = (float)(2.0 * PI / ((float)n1)); B\<Q ;RI2;  
    gamma = (float)(2.0 * PI / ((float)n2)); !,l9@eJQ  
    for (k1 = 0; k1 < n1; k1++) +1Vjw'P  
    { @AK n@T5  
        tmpBeta = beta * k1; pA`+hQNN  
        for (k2 = 0; k2 < n2; k2++) N8!cO[3Oh  
        { ;KOLNi-B&  
            idx = shift * (n2 * k1 + k2); uXI_M )  
            x_out[idx] = 0.0; k ]W[`  
            x_out[idx + 1] = 0.0; R?v>Q` Qi  
            tmpGamma = gamma * k2; 2Gz}T _e  
            tmpAlpha = alpha * k2; M^MdRu  
            for (m1 = 0; m1 < n1; m1++) ^g*pGrl#  
            { d{rQzia"mV  
                tmpRe = 0.0; ?f#y1m  
                tmpIm = 0.0; _6_IP0;  
                for (m2 = 0; m2 < n2; m2++) 0n@rLF  
                { rW0kA1=E  
                    angle = tmpGamma * m2; JCz@s~f\y  
                    index = shift * (n1 * m2 + m1); 2]I4M[|&z  
                    cosAngle = cosf(angle); 7bqBk,`9  
                    sinAngle = sinf(angle); (>F%UY  
                    tmpRe += x_in[index] * cosAngle + x_in[index + 1] * sinAngle; =2[7 E  
                    tmpIm += x_in[index + 1] * cosAngle - x_in[index] * sinAngle; &?VQ,+[ <  
                } 7P" | J\  
                angle = tmpAlpha * m1; W^fuScG)c  
                cosAngle = cosf(angle); Q&MZN);.  
                sinAngle = sinf(angle); [OHxonU  
                phaseRe = cosAngle * tmpRe + sinAngle * tmpIm; dArDP[w  
                phaseIm = cosAngle * tmpIm - sinAngle * tmpRe; 6^uq?  
                angle = tmpBeta * m1; ;} und*q  
                cosAngle = cosf(angle); PH`9MXh  
                sinAngle = sinf(angle); 9v?N+Rb  
                x_out[idx] += (cosAngle * phaseRe + sinAngle * phaseIm); }~#pEX~j*  
                x_out[idx + 1] += (cosAngle * phaseIm - sinAngle * phaseRe); MG[o%I96  
            } 1v,Us5s<"6  
        } y|CP;:f;  
    } W4[V}s5u  
    return FFT_OK; j]*j}%hz  
} [`p=(/I&L  
bSsh^Z  
/* cU ? 0(z7  
// Inverse 1-dimensional FFT fNb`X  
// ]d,S749(s  
// API 0dhF&*h|L  
// int fftInverse(float *x_in, float *x_out, int n, int shift); [!}:KD2yX  
// INPUT +6UVn\9Q  
// x_in              - Fourier image of 1d input signal(contains 2n elements B+[A]dgS  
                       in order Re(x_in[0]), Im(x_in[0]), ^dP KDrKxh  
                       Re(x_in[1]), Im(x_in[1]) and etc.) b'J'F;zh>  
// n                 - number of elements for searching counter FFT image JAAI_gSR3  
// shift             - shift between input elements '&.#  
// OUTPUT RQ'exc2x0  
// x_in              - input signal (contains n elements) Swp;HW7x  
// RESULT *GxTX3i}vc  
// Error status N` aF{3[  
*/ ox:[f9.5  
int fftInverse(float *x_in, float *x_out, int n, int shift) M@4UGM`J  
{ .mDM[e@'  
    int n1, n2, res, k1, k2, m1, m2, index, idx; A;/-u<f  
    float alpha, beta, gamma, angle, cosAngle, sinAngle; ?shIj;c[  
    float tmpRe, tmpIm, phaseRe, phaseIm; pX&pLaF  
    res = getMultipliers(n, &n1, &n2); 1QmH{jM  
    if (res == FFT_OK) PUo/J~v  
    { si&S%4(  
        fftInverse(x_in, x_out, n1, shift); Kl2lbe7  
        fftInverse(x_in, x_out, n2, shift); 66.5QD0  
    } cgl*t+o&  
    alpha = (float)(2.0f * PI / ((float)n)); 3pK*~VK  
    beta = (float)(2.0f * PI / ((float)n1)); w" Soe U  
    gamma = (float)(2.0f * PI / ((float)n2)); ,hq)1u  
    for (m1 = 0; m1 < n1; m1++) .so[I  
    { kGd<5vCs  
        for (m2 = 0; m2 < n2; m2++) S+'rG+NJ  
        { GP&vLt51  
            idx = (n1 * m2 + m1) * shift; dxZu2&gi  
            x_out[idx] = 0.0; ?;vgUO  
            x_out[idx + 1] = 0.0; Mk=mT3=#  
            for (k2 = 0; k2 < n2; k2++) :JfE QIN  
            { D\[h:8k  
                tmpRe = 0.0; EL8NZ%:v:  
                tmpIm = 0.0; hQ(qbt{e  
                for (k1 = 0; k1 < n1; k1++) q EP 4  
                { &}?$i7x5  
                    angle = beta * k1 * m1; M/):e$S  
                    index = shift *(n2 * k1 + k2); ?Y:8eD"*  
                    sinAngle = sinf(angle); 2Fz|fW_  
                    cosAngle = cosf(angle); p=C%Hmd5E  
                    tmpRe += x_in[index] * cosAngle - x_in[index + 1] * sinAngle; 7UL qo>j  
                    tmpIm += x_in[index] * sinAngle + x_in[index + 1] * cosAngle; txcf=)@>V  
                } ] )F7)  
                angle = alpha * m1 * k2; x5QaM.+=J  
                sinAngle = sinf(angle); AgRjr"hF*e  
                cosAngle = cosf(angle); z fwS  
                phaseRe = cosAngle * tmpRe - sinAngle * tmpIm; j:,NE(DF  
                phaseIm = cosAngle * tmpIm + sinAngle * tmpRe; Pl<; [cB  
                angle = gamma * k2 * m2; @FC"nM  
                sinAngle = sinf(angle); NM0tp )h  
                cosAngle = cosf(angle); !A>z(eIsv`  
                x_out[idx] += cosAngle * phaseRe - sinAngle * phaseIm; 'Fs)Rx}\0  
                x_out[idx + 1] += cosAngle * phaseIm + sinAngle * phaseRe; p/2jh&  
            } m$9w"8R  
            x_out[idx] /= n; quvanx V-L  
            x_out[idx + 1] /= n; 3d-%>?-ee  
        } eL4NB$Fb  
    } ?d4m!HgR   
    return FFT_OK; 6<'rG''  
} v^ /Q 8Q  
`60gFVu  
/* hXb%;GL  
// 2-dimensional FFT avy"r$v_&  
// <,AS8^$X[  
// API %0 #XPc("  
// int fft2d(float *x_in, float *x_out, int numRows, int numColls); <BO)E(  
// INPUT 0W3 i()  
// x_in              - input signal (matrix, launched by rows) xil[#W]7Ge  
// numRows           - number of rows w=|GJ 0  
// numColls          - number of collumns 'kYwz;gp  
// OUTPUT DAwqo.m  
// x_out             - output signal (contains (2 * numRows * numColls) elements wZ4tCZA  
                       in order Re(x_in[0][0]), Im(x_in[0][0]), I+ es8  
                       Re(x_in[0][1]), Im(x_in[0][1]) and etc.) pDQ}*   
// RESULT *xE,sj+(  
// Error status i5 >+}$1  
*/ 6YuY|JD  
int fft2d(float *x_in, float *x_out, int numRows, int numColls) hLDA]s  
{ [>^PRs  
    int i, size; Zh NdB  
    float *x_outTmp; A~Xq,BxCV  
    size = numRows * numColls; bu&t'?z x!  
    x_outTmp = (float *)malloc(sizeof(float) * (2 * size)); `z0{S!  
    for (i = 0; i < numRows; i++) v`V7OD#:j]  
    { (~)%Fo9X"  
        fft(x_in + i * 2 * numColls, mR8W]'gl.L  
            x_outTmp + i * 2 * numColls, |0{u->+ )  
            numColls, 2); [TF8'jI0  
    } aZKOY  
    for (i = 0; i < numColls; i++) =SD\Q!fA  
    { @<M*qK1h  
        fft(x_outTmp + 2 * i, ds[QwcV9-  
            x_out + 2 * i, z q1mmFIO  
            numRows, 2 * numColls); \V2,pi8'v  
    } m,')&{Rd  
    free(x_outTmp); ;NV'W]  
    return FFT_OK; o{*ay$vA]  
} +Z!;P Z6  
eQO#Qso]  
/* y[O-pD`  
// Inverse 2-dimensional FFT ^MD;"A<  
// M,3wmW&d6  
// API DWt*jX*  
// int fftInverse2d(float *x_in, float *x_out, int numRows, int numColls); e75UMWaeC  
// INPUT "Lh   
// x_in              - Fourier image of matrix (contains (2 * numRows * numColls) Ufo>|A 6;$  
                       elements in order Re(x_in[0][0]), Im(x_in[0][0]), 1\dn 1Hh  
                       Re(x_in[0][1]), Im(x_in[0][1]) and etc.) /,5Z-Z*wq  
// numRows           - number of rows }a&mY^  
// numColls          - number of collumns &X`u9 V  
// OUTPUT v&g0ta@  
// x_out             - initial signal (matrix, launched by rows) g^kx(p<u`  
// RESULT Y{f7 f'_  
// Error status  17hTr  
*/ ,]Zp+>{  
int fftInverse2d(float *x_in, float *x_out, int numRows, int numColls) 2aw&F Z?  
{ A1cb"N^  
    int i, size; 2 Tvvq(?T  
    float *x_outTmp; (#(O r  
    size = numRows * numColls; AB.(CS=i  
    x_outTmp = (float *)malloc(sizeof(float) * (2 * size)); W VkR56  
    for (i = 0; i < numRows; i++) mnF}S5[9  
    { TUp%FJXA|  
        fftInverse(x_in + i * 2 * numColls, eukA[nO7G  
            x_outTmp + i * 2 * numColls, ;n#%G^!H  
            numColls, 2); sCH)gr@gJ^  
    } FQeYx-7  
    for (i = 0; i < numColls; i++) i4Z4xTn  
    { ~el-*=<m  
        fftInverse(x_outTmp + 2 * i, Y'"N"$n'_  
            x_out + 2 * i, V*jsq[q=  
            numRows, 2 * numColls); X=p"5hhfn  
    } M<8ML!N0;t  
    free(x_outTmp);   &LQ%  
    return FFT_OK; l\q} |o  
}
最佳答案奖励: (+1) 学点
级别: 北风工程师

UID: 474133
精华: 0
发帖: 541
威望: 1194 点
学点: 844 点
贡献: 0 点
好评: 0 点
学币: 0 个
注册时间: 2014-07-13
最后登录: 2014-09-01
板凳(2楼)  发表于: 2014-07-28 16:19||

老师看不懂啊,能说详细点吗?
级别: 北风工程师

UID: 474135
精华: 0
发帖: 543
威望: 1108 点
学点: 666 点
贡献: 0 点
好评: 0 点
学币: 0 个
注册时间: 2014-07-13
最后登录: 2014-08-25
地板(3楼)  发表于: 2014-07-28 16:20||

那该怎么****成控件啊
级别: 北风爱好者

UID: 579634
精华: 0
发帖: 1
威望: 1 点
学点: 3 点
贡献: 0 点
好评: 0 点
学币: 0 个
注册时间: 2015-05-18
最后登录: 2015-05-27
地下室(4楼)  发表于: 2015-05-18 20:28||

回 楼主(448832164) 的帖子

你好  请问你弄好了吗?  我今年也要弄这个软件  我看了帖子   但还不知道怎么弄    如果你弄好了还留着  能不能发给我  拜托了