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

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

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

大学软件设计实验题目,有没有好人帮忙啊 c_lHj#A(l  
g=*jKSZ  
要求:输入给定信号(数组),基于FFT快速频谱计算,给出频谱图显示。并****成控件方便调用。 S-Uod y  
格式:设计题目     0[;2dc  
任务要求     E$8JrL  
实验设备及软件     FG?Mc'r&  
参考文献
此帖悬赏结束
最佳答案: 1 学点
最佳答案获得者: 慕容紫英
级别: 北风资深工程师


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

先搜索下载安装OpenCV $y6 <2w%b  
然后参考C:\Program Files\OpenCV\modules\objdetect\src\fft.cpp (rFiHv5  
C/C++ code @%fTdneH  
{C&U q#V  
|8f}3R 9  
#include "precomp.hpp" S?CT6moXA  
#include "_lsvm_fft.h" i.'"`pn_  
/[dMw *SRz  
int getEntireRes(int number, int divisor, int *entire, int *res) `Pc6 G*p  
{ S3/%;=|  
    *entire = number / divisor; pl%!AY'oE>  
    *res = number % divisor; x</4/d  
    return FFT_OK; |dQz(z&6{5  
} .;g kV-]  
#w.0Cc  
int getMultipliers(int n, int *n1, int *n2) O)`L( x  
{ !#pc@(rE  
    int multiplier, i; =s!0EwDH3  
    if (n == 1) (mp  
    { kJmwR  
        *n1 = 1; MlYm\x8{M  
        *n2 = 1; I'*,<BPG  
        return FFT_ERROR; // n = 1 IQU1 JVk Z  
    } /i8OyRpSyk  
    multiplier = n / 2; . .5~ x~O  
    for (i = multiplier; i >= 2; i--) *-PjcF}Y  
    { mH\zSk  
        if (n % i == 0) MJ ch Z  
        { )1!<<;@0  
            *n1 = i; }0pp"[JU  
            *n2 = n / i; 3v\P6  
            return FFT_OK; // n = n1 * n2 tkZUjQIX  
        } xh:I]('R  
    } +# 'w} P  
    *n1 = 1; VIdKe&,  
    *n2 = n; @Pk<3.S0  
    return FFT_ERROR; // n - prime number )Xg5=zn$  
} >BO$tbU5b  
5c3-?u!  
/* eMnK@J  
// 1-dimensional FFT qr4 lr!#t  
//  .x%w#  
// API cy.r/Z}  
// int fft(float *x_in, float *x_out, int n, int shift); Ez~5ax7x  
// INPUT SbGdcCB  
// x_in              - input signal ^O*-|ecA  
// n                 - number of elements for searching Fourier image ]O@iT= *3  
// shift             - shift between input elements Y]L4,V  
// OUTPUT rs?Dn6:;B  
// x_out             - output signal (contains 2n elements in order %<-OdyM  
                       Re(x_in[0]), Im(x_in[0]), Re(x_in[1]), Im(x_in[1]) and etc.) WGn=3(4  
// RESULT =oI[E~1<  
// Error status '27$x&6>S  
*/ uQ-GJI^t  
int fft(float *x_in, float *x_out, int n, int shift) <z\SKR[  
{ 6}-No  
    int n1, n2, res, k1, k2, m1, m2, index, idx; y/\b0&  
    float alpha, beta, gamma, angle, cosAngle, sinAngle; q  
    float tmpGamma, tmpAlpha, tmpBeta; SM8N*WdiU  
    float tmpRe, tmpIm, phaseRe, phaseIm; 4+q,[m-$(  
    res = getMultipliers(n, &n1, &n2); 3`yO&upk  
    if (res == FFT_OK) ?)-6~p 4N  
    { 0YFXF  
        fft(x_in, x_out, n1, shift); N_K9H1 r  
        fft(x_in, x_out, n2, shift); N_NN0  
    } ^}Vc||S  
    alpha = (float)(2.0 * PI / ((float)n)); _ +DL   
    beta = (float)(2.0 * PI / ((float)n1)); je^VJ&ac  
    gamma = (float)(2.0 * PI / ((float)n2)); Ztmh z_u7  
    for (k1 = 0; k1 < n1; k1++) GP c B(  
    { ?@4Mt2Z\  
        tmpBeta = beta * k1; pF8$83S  
        for (k2 = 0; k2 < n2; k2++) 4Y?2u  
        { %TQ4 ZFD3  
            idx = shift * (n2 * k1 + k2); Hi={(Z5tC4  
            x_out[idx] = 0.0; YCiG~y/~  
            x_out[idx + 1] = 0.0; g@^y$wt  
            tmpGamma = gamma * k2; sPi  
            tmpAlpha = alpha * k2; `15}jTi  
            for (m1 = 0; m1 < n1; m1++) >`UqS`YQK  
            { %>Gb]dv?  
                tmpRe = 0.0; d]e36Dwk  
                tmpIm = 0.0; a%Q`R;W  
                for (m2 = 0; m2 < n2; m2++) Pg T3E  
                { "<0!S~]  
                    angle = tmpGamma * m2; Y^Buz<OiG  
                    index = shift * (n1 * m2 + m1); 8*u'D@0  
                    cosAngle = cosf(angle); Hj>9#>b  
                    sinAngle = sinf(angle); Ld*Ds!*'/  
                    tmpRe += x_in[index] * cosAngle + x_in[index + 1] * sinAngle; ^5]9B<i[Y  
                    tmpIm += x_in[index + 1] * cosAngle - x_in[index] * sinAngle; ,JdBVt  
                }  Culv/  
                angle = tmpAlpha * m1; kEq~M10  
                cosAngle = cosf(angle); >97YK =  
                sinAngle = sinf(angle); <~uzHg%Y  
                phaseRe = cosAngle * tmpRe + sinAngle * tmpIm; I*TTD]e'X  
                phaseIm = cosAngle * tmpIm - sinAngle * tmpRe; 0x~+=GUN  
                angle = tmpBeta * m1; X'$H'[8;C  
                cosAngle = cosf(angle); mh"PAp  
                sinAngle = sinf(angle); 'Grej8  
                x_out[idx] += (cosAngle * phaseRe + sinAngle * phaseIm); T%%EWa<a  
                x_out[idx + 1] += (cosAngle * phaseIm - sinAngle * phaseRe); +!u9_?Tp  
            } 1sg:8AA  
        } ,Dv*<La`\  
    } Fy5:|C N  
    return FFT_OK; %R4 \[e  
} >6Pe~J5,:  
-%J9!(  
/* GCYXDovh  
// Inverse 1-dimensional FFT }OIe!  
// t"Du  
// API 0@?m"|G  
// int fftInverse(float *x_in, float *x_out, int n, int shift); [@qjy*5p  
// INPUT ?a,#p  
// x_in              - Fourier image of 1d input signal(contains 2n elements 1@I#Fv  
                       in order Re(x_in[0]), Im(x_in[0]), rOLZiET  
                       Re(x_in[1]), Im(x_in[1]) and etc.) U0 -RG  
// n                 - number of elements for searching counter FFT image pSQX  
// shift             - shift between input elements w|G 7h=  
// OUTPUT uM 'n4oH  
// x_in              - input signal (contains n elements) jl}9R]Y_2  
// RESULT #7H0I8  
// Error status 1:<n(?5JI  
*/ =k d-rIBc  
int fftInverse(float *x_in, float *x_out, int n, int shift) =4+2y '  
{ j{FRD8]V  
    int n1, n2, res, k1, k2, m1, m2, index, idx; Z L0Vx6Ph  
    float alpha, beta, gamma, angle, cosAngle, sinAngle; =g6~2p=H  
    float tmpRe, tmpIm, phaseRe, phaseIm; T0fm6 J  
    res = getMultipliers(n, &n1, &n2); 9+*{3 t  
    if (res == FFT_OK) OD[=fR|cp  
    { :KC]1_zqR  
        fftInverse(x_in, x_out, n1, shift); <z60E vHg  
        fftInverse(x_in, x_out, n2, shift); ? .B t.  
    } "PTEt{qn  
    alpha = (float)(2.0f * PI / ((float)n)); 19R~&E's  
    beta = (float)(2.0f * PI / ((float)n1)); rgXX,+cO  
    gamma = (float)(2.0f * PI / ((float)n2)); uUp>N^mmVH  
    for (m1 = 0; m1 < n1; m1++) KgYQxEbIW  
    { ]srL>29_b  
        for (m2 = 0; m2 < n2; m2++) DJdhOLx  
        { <}&J|()  
            idx = (n1 * m2 + m1) * shift; Cs"ivET  
            x_out[idx] = 0.0; |4BD  
            x_out[idx + 1] = 0.0; rvhMu}.  
            for (k2 = 0; k2 < n2; k2++) 6E ^m*la%  
            { u-.5rH l  
                tmpRe = 0.0; 6&i])iH  
                tmpIm = 0.0; !+Cc^{  
                for (k1 = 0; k1 < n1; k1++) Tl"r#  
                { 6C"${}S F`  
                    angle = beta * k1 * m1; e GAto  
                    index = shift *(n2 * k1 + k2); 9;*B*S~znW  
                    sinAngle = sinf(angle); EN ^L.q9#  
                    cosAngle = cosf(angle); to_dNJbv  
                    tmpRe += x_in[index] * cosAngle - x_in[index + 1] * sinAngle; YJwI@E(l$  
                    tmpIm += x_in[index] * sinAngle + x_in[index + 1] * cosAngle; VtN@B*  
                } 7/]Ra  
                angle = alpha * m1 * k2; ~.e~YI80  
                sinAngle = sinf(angle); 8rBa}v9  
                cosAngle = cosf(angle); Ug#B ( }/  
                phaseRe = cosAngle * tmpRe - sinAngle * tmpIm; u1'l 4VgT  
                phaseIm = cosAngle * tmpIm + sinAngle * tmpRe; I+ Qt5Ox  
                angle = gamma * k2 * m2; R Ee~\n+P^  
                sinAngle = sinf(angle); 66W J=? JV  
                cosAngle = cosf(angle); 6ypHH 2X  
                x_out[idx] += cosAngle * phaseRe - sinAngle * phaseIm; `]6W*^'PD  
                x_out[idx + 1] += cosAngle * phaseIm + sinAngle * phaseRe; jX$U)O  
            } k^q~ 2  
            x_out[idx] /= n; yJ; ;&  
            x_out[idx + 1] /= n; ~}D"8[ABj  
        } HN;f~EQT  
    } 2xy{g&G  
    return FFT_OK; <gvgr4@^yR  
} 9,>c;7s X  
?56;<%0  
/* R6GlQ G  
// 2-dimensional FFT C?g*c  
// Cw.DLg  
// API 1X&scVw  
// int fft2d(float *x_in, float *x_out, int numRows, int numColls); R6o07.]  
// INPUT KAT ^vbR  
// x_in              - input signal (matrix, launched by rows) ,0,& L  
// numRows           - number of rows J rYL8 1  
// numColls          - number of collumns a\ MJh+K  
// OUTPUT 8Sf}z@~]  
// x_out             - output signal (contains (2 * numRows * numColls) elements M~saYJio  
                       in order Re(x_in[0][0]), Im(x_in[0][0]), (H|^Ow5  
                       Re(x_in[0][1]), Im(x_in[0][1]) and etc.) TDR#'i  
// RESULT ]>(pQD  
// Error status S: g 2V  
*/ <;Td8T;  
int fft2d(float *x_in, float *x_out, int numRows, int numColls) ~05(92bK  
{ mL s>RR#b  
    int i, size; /-ewCCzZV  
    float *x_outTmp; =\jPnov!  
    size = numRows * numColls; @7Nc*-SM  
    x_outTmp = (float *)malloc(sizeof(float) * (2 * size)); v`"BXSmp{  
    for (i = 0; i < numRows; i++) u |ru$cIo  
    { 5[+E?4,&  
        fft(x_in + i * 2 * numColls, TGG-rA6@Lx  
            x_outTmp + i * 2 * numColls, GmN~e*x>p  
            numColls, 2); tjDCfJx*  
    } G:PcV_ihx  
    for (i = 0; i < numColls; i++) yuZh ak  
    { qzE -y-9@  
        fft(x_outTmp + 2 * i, ;MKfssG  
            x_out + 2 * i, ^ G>/;mZ  
            numRows, 2 * numColls); ;u?H#\J,  
    } 9D& 22hL4  
    free(x_outTmp); p~t5PU*(  
    return FFT_OK; ! lm0zR  
} @1peJJ{  
'miY"L:| O  
/* @{^6_n+gT%  
// Inverse 2-dimensional FFT [YQ` `  
// CEb al\R  
// API k3B]u.Lo  
// int fftInverse2d(float *x_in, float *x_out, int numRows, int numColls); U3ao:2zP  
// INPUT $x1PU67  
// x_in              - Fourier image of matrix (contains (2 * numRows * numColls) ew6\Z$1c~  
                       elements in order Re(x_in[0][0]), Im(x_in[0][0]), 9|LV x3]  
                       Re(x_in[0][1]), Im(x_in[0][1]) and etc.) zF=E5TL-,4  
// numRows           - number of rows A/U,|  
// numColls          - number of collumns tcS7 @^'  
// OUTPUT r081.<  
// x_out             - initial signal (matrix, launched by rows) XnI)s^  
// RESULT zJa,kN|m  
// Error status {nlqQ.jO  
*/ ){{]3r  
int fftInverse2d(float *x_in, float *x_out, int numRows, int numColls) qx3`5)ef  
{ C Ejf&n  
    int i, size; =WP`i29j9}  
    float *x_outTmp; _^pg!j[Fy}  
    size = numRows * numColls; h$y0>eMWs  
    x_outTmp = (float *)malloc(sizeof(float) * (2 * size)); :raYt5n1,y  
    for (i = 0; i < numRows; i++) ~Uw <E:?v  
    { /6@Wm? `DB  
        fftInverse(x_in + i * 2 * numColls, F`\7&'I  
            x_outTmp + i * 2 * numColls, aI0}E O  
            numColls, 2); $s-HG[lX[  
    } MX{p)(HW  
    for (i = 0; i < numColls; i++) Ss~dK-{e7  
    { w- .=u3  
        fftInverse(x_outTmp + 2 * i, AmmUoS\  
            x_out + 2 * i, (qM(~4|`  
            numRows, 2 * numColls); OCVF+D :  
    } Z#lZn!EbK  
    free(x_outTmp); =5sUpP V(  
    return FFT_OK; gM<*(=x'  
}
最佳答案奖励: (+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) 的帖子

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