开发工具:
文件大小: 14kb
下载次数: 0
上传时间: 2009-03-03
详细说明: fft程序, Dim REX(512) 'REX[ ] holds the real part of the frequency domain Dim IMX(512) 'IMX[ ] holds the imaginary part of the frequency domain Const N = 512 Public Sub fft() pi = 3.14159265 'Set constants 1000 'THE FAST FOURIER TRANSFORM 'copyright © 1997-1999 by California Technical Publishing 'published with permission from Steven W Smith, www.dspguide.com 'GUI by logix4u , www.logix4u.net 'modified by logix4u, www.logix4.net 1010 'Upon entry, N% contains the number of points in the DFT, REX[ ] and 1020 'IMX[ ] contain the real and imaginary parts of the input. Upon return, 1030 'REX[ ] and IMX[ ] contain the DFT output. All signals run from 0 to N%-1. 1060 NM1% = N% - 1 1070 ND2% = N% / 2 1080 M% = CInt(Log(N%) / Log(2)) 1090 J% = ND2% 1100 ' 1110 For i% = 1 To N% - 2 'Bit reversal sorting 1120 If i% >= J% Then GoTo 1190 1130 TR = REX(J%) 1140 TI = IMX(J%) 1150 REX(J%) = REX(i%) 1160 IMX(J%) = IMX(i%) 1170 REX(i%) = TR 1180 IMX(i%) = TI 1190 K% = ND2% 1200 If K% > J% Then GoTo 1240 1210 J% = J% - K% 1220 K% = K% / 2 1230 GoTo 1200 1240 J% = J% + K% 1250 Next i% 1260 ' 1270 For L% = 1 To M% 'Loop for each stage 1280 LE% = CInt(2 ^ L%) 1290 LE2% = LE% / 2 1300 UR = 1 1310 UI = 0 1320 SR = Cos(pi / LE2%) 'Calculate sine & cosine values 1330 SI = -Sin(pi / LE2%) 1340 For J% = 1 To LE2% 'Loop for each sub DFT 1350 JM1% = J% - 1 1360 For i% = JM1% To NM1% Step LE% 'Loop for each butterfly 1370 IP% = i% + LE2% 1380 TR = REX(IP%) * UR - IMX(IP%) * UI 'Butterfly calculation 1390 TI = REX(IP%) * UI + IMX(IP%) * UR 1400 REX(IP%) = REX(i%) - TR 1410 IMX(IP%) = IMX(i%) - TI 1420 REX(i%) = REX(i%) + TR 1430 IMX(i%) = IMX(i%) + TI 1440 Next i% 1450 TR = UR 1460 UR = TR * SR - UI * SI 1470 UI = TR * SI + UI * SR 1480 Next J% 1490 Next L% 1500 ' End Sub Private Sub btn_clr_Click() ipplot.Cls FuncGen.Clear End Sub Private Sub btn_generate_Click() FuncGen.SamplingRate = CInt(txtsamp.Text) FuncGen.amplitude = Slideramp.Value If opt_sin.Value = True Then FuncGen.GenSine CInt(txtfreq.Text) End If If opt_cos.Value = True Then FuncGen.GenCos CInt(txtfreq.Text) End If If opt_impulse.Value = True Then FuncGen.GenImpulse Val(txt_impulsepos.Text) End If If Opt_sqr.Value = True Then FuncGen.GenSquare CInt(txtfreq.Text) End If ipplot.Cls plotip End Sub Private Sub Command1_Click() output.Cls End Sub Private Sub Command2_Click() On Error Resume Next If Optreal.Value = True Then output.ForeColor = vbRed For cnt = 0 To 156 outputarray(cnt) = REX(cnt) Next cnt End If If Optimg.Value = True Then output.ForeColor = vbWhite For cnt = 0 To 156 outputarray(cnt) = IMX(cnt) Next cnt End If If Optmag.Value = True Then output.ForeColor = vbYellow For cnt = 0 To 156 outputarray(cnt) = Sqr((IMX(cnt) * IMX(cnt)) + (REX(cnt) * REX(cnt))) Next cnt End If If Optphase.Value = True Then output.ForeColor = vbCyan For cnt = 0 To 156 outputarray(cnt) = Atn(IMX(cnt) / REX(cnt)) Next cnt End If If Optpower.Value = True Then output.ForeColor = vbGreen For cnt = 0 To 156 outputarray(cnt) = (IMX(cnt) * IMX(cnt)) + (REX(cnt) * REX(cnt)) Next cnt End If For cnt = 0 To 256 If (maxvalue < outputarray(cnt)) Then maxvalue = outputarray(cnt) End If Next cnt oldval = (2600 / (2 * Screen.TwipsPerPixelY)) - (outputarray(1) * ((950 / Screen.TwipsPerPixelY) / maxvalue)) For cnt = 1 To 256 output.Line (cnt - 1, oldval)-(cnt, (2600 / (2 * Screen.TwipsPerPixelY)) - (outputarray(cnt) * ((950 / Screen.TwipsPerPixelY) / maxvalue))) oldval = (2600 / (2 * Screen.TwipsPerPixelY)) - (outputarray(cnt) * ((950 / Screen.TwipsPerPixelY) / maxvalue)) Next cnt End Sub Private Sub Command3_Click() MsgBox "Developed and published by : " + vbNewLine + "LOGIX4U" + vbNewLine + "www.logix4u.net" + vbNewLine + vbNewLine + "Algorithms by : " + vbNewLine + "Steven W Smith " + vbNewLine + "www.dspguide.com", vbInformation, "About" End Sub Private Sub Command4_Click() On Error Resume Next Label5.Visible = True DoEvents If Opthamm.Value = True Then FuncGen.ApplyHamming ipplot.Cls plotip End If If Opthann.Value = True Then FuncGen.ApplyHanning ipplot.Cls plotip End If If Optblack.Value = True Then FuncGen.ApplyBlackman ipplot.Cls plotip End If For cnt = 1 To 512 REX(cnt) = FuncGen.Samples(cnt) IMX(cnt) = 0 Next cnt fft If Optreal.Value = True Then output.ForeColor = vbRed For cnt = 0 To 156 outputarray(cnt) = REX(cnt) Next cnt End If If Optimg.Value = True Then output.ForeColor = vbWhite For cnt = 0 To 156 outputarray(cnt) = IMX(cnt) Next cnt End If If Optmag.Value = True Then output.ForeColor = vbYellow For cnt = 0 To 156 outputarray(cnt) = Sqr((IMX(cnt) * IMX(cnt)) + (REX(cnt) * REX(cnt))) Next cnt End If If Optphase.Value = True Then output.ForeColor = vbCyan For cnt = 0 To 156 outputarray(cnt) = Atn(IMX(cnt) / REX(cnt)) Next cnt End If If Optpower.Value = True Then output.ForeColor = vbGreen For cnt = 0 To 156 outputarray(cnt) = Sqr((IMX(cnt) * IMX(cnt)) + (REX(cnt) * REX(cnt))) Next cnt End If For cnt = 0 To 256 If (maxvalue < outputarray(cnt)) Then maxvalue = outputarray(cnt) End If Next cnt oldval = (2600 / (2 * Screen.TwipsPerPixelY)) - (outputarray(1) * ((950 / Screen.TwipsPerPixelY) / maxvalue)) For cnt = 1 To 256 output.Line (cnt - 1, oldval)-(cnt, (2600 / (2 * Screen.TwipsPerPixelY)) - (outputarray(cnt) * ((950 / Screen.TwipsPerPixelY) / maxvalue))) oldval = (2600 / (2 * Screen.TwipsPerPixelY)) - (outputarray(cnt) * ((950 / Screen.TwipsPerPixelY) / maxvalue)) Next cnt Label5.Visible = False End Sub Private Sub Form_Activate() ipplot.Line (0, 1450 / Screen.TwipsPerPixelY)-(10000, 1450 / Screen.TwipsPerPixelY), vbRed End Sub Private Sub Form_Paint() On Error Resume Next Dim maxvalue, oldval As Double ipplot.Cls plotip End Sub Private Sub opt_impulse_Click() If opt_impulse.Value = True Then txt_impulsepos.Enabled = True End If End Sub ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.