j=j-k
k=k/2
Wend
j=j+k
Nexti
Forl=1Tom
LE=2^l
L1=LE/2
UR=1#
UI=0#
wr=Cos(Pi/L1)
wi=SN*Sin(Pi/L1)
Forj=1ToL1
Fori=jTonStepLE
IP=i+L1
TR=AR(IP)*UR-AI(IP)*UI
TI=AI(IP)*UR+AR(IP)*UI
AR(IP)=AR(i)-TR
AI(IP)=AI(i)-TI
AR(i)=AR(i)+TR
AI(i)=AI(i)+TI
Nexti
US=UR
UR=US*wr-UI*wi
UI=UI*wr+US*wi
Nextj
Nextl
IfSN<>-1Then
Fori=1Ton
AR(i)=AR(i)/n
AI(i)=AI(i)/n
Nexti
EndIf
EndFunction
2)数据保存和读取:
PublicSubload()'数据保存
Dimtemp
Dimi,jAsInteger
IfCount<>0Then
res=MsgBox("当前数据数否保存?
",vbYesNo)
Ifres=6Then
Callstore
EndIf
EndIf
CD.ShowOpen
i=0
IfCD.FileName<>""Then
OpenCD.FileNameForInputAs#1
DoWhileNotEOF
(1)
Input#1,temp
data(i)=temp
i=i+1
Loop
Close1
Text4=maxdata()
Text5=mindata()
Text6=avdata()
Text7.Text=sample_length
Text8.Text=sample_fre
MsgBox("数据读取完成!
")
EndIf
EndSub
PublicSubstore()'数据读取
DimstrAsString
j=0
g=sample_length
Ifsample_length<>0Then
str=Format(Now,"yyyymmddhhmmss")&".txt"
OpenstrForAppendAs#1
DoWhilej<>g
Print#1,data(j)
j=j+1
Loop
Close1
MsgBox("完成数据储存!
")
Else
MsgBox("无数据,无法储存!
")
EndIf
EndSub
3)AD数据采集模块
temp=AC_6111_AD(NTportio,cardid(0),4000/sample_fre,sample_path,sample_path,3,0,0,0,0,0,0,Data1(0),sample_length)
Fori=0Tosample_length'转换数据,16位转化为12位
data(i)=((Data1(i)And&HFFF0&)/16-2048)/2048#*10#'设置为显示到-10V到10V
Nexti
4)数据的时域曲线显示和频率周期的计算
PublicSubshi()
Text10.Visible=False
Picture2.Visible=True
Picture2.BackColor=RGB(255,255,255)
Picture2.Scale(0,10)-(512,-10)
Picture2.Line(0,0)-(512,0)
Picture2.Line(0,10)-(0,-10)
'绘制与x轴平行的直线,并标记y轴
Fori=0To10
Picture2.Line(0,10-2*i)-(512,10-2*i)
Picture2.CurrentX=5
Picture2.CurrentY=10-2*i
Picture2.Print(10-2*i)&"V"
Nexti
'绘制与y轴平行的直线,并标记x轴
DimjAsSingle
Forj=0To512Step30'''一个格含50个数
Picture2.Line(j,-10)-(j,10),vbBlue
Picture2.CurrentY=0
Picture2.CurrentX=j
IfAbs(j/sample_fre)<1Then
Picture2.PrintFormat(j/sample_fre,"#0.####")
Else
Picture2.PrintFormat(j/sample_fre,"##.####")
EndIf
Nextj
'绘制波形
Dimt1,t2,t3AsInteger
DimperiodAsDouble
period=1/sample_fre
Fori=1Tosample_length-1
Ifdata(i)*data(i+1)<=0Anddata(i)<0Andt1=0Then'采样值发生正跳变
t2=i
t1=t1+1
EndIf
Ifdata(i)*data(i+1)<=0Anddata(i)>0Andt1=1Then'采样值发生负跳变
t3=i
t1=t1+1
EndIf
Nexti
interv=2*Abs(t3-t2)*period'周期
Ifinterv<>0Thenfrequency=1/interv'频率
Text4=maxdata()&"V"
Text5=mindata()&"V"
Text6=avdata()&"V"
Text7.Text=sample_length
Text8.Text=sample_fre
Fori=1Tosample_lengthStep1
data(i)=data(i)*zy
Nexti
Fori=1Tosample_lengthStep1
Picture2.Line(i-1,data(i-1))-(i,data(i)),vbRed
Nexti
Text9.Text=interv
Text11.Text=frequency
'CL.Add(data(j)/10*s1)
'DRW.Draw
'Nextj
EndSub
5)FFT曲线显示
PublicSubfft()
ConstfftIn=2048
DimiAsInteger
Dimxr(2048)AsDouble
Dimxi(2048)AsDouble
'赋值,IaIn(i)是采得的数据。
Fori=0To2048
xr(i)=100*data(i)
xi(i)=0
Next
CallFFT0(xr(),xi(),2048,1)
'绘图
PicI_FFT.Scale(0,100)-(fftIn-1,-10)
PicI_FFT.DrawWidth=2
Fori=0TofftIn-1
PicI_FFT.Line(i,Abs(xr(i)))-(i+1,Abs(xr(i+1))),vbBlue
Nexti
EndSub
6)导出图形
PrivateSubCommand4_Click()
CommonDialog3.ShowSave''显示另存为对话框
CommonDialog3.Filter="(*.bmp)|*.bmp"
FileName=CommonDialog3.FileName
SavePicturePicture2.Image,"filename.BMP"
'EndSub
7)截图
PrivateSubCommand1_Click()
DoEvents
BitBltForm2.hDC,0,0,Screen.Width,Screen.Height,GetDC(GetDesktopWindow),0,0,&HCC0020
SetWindowPosForm2.hWnd,HWND_TOPMOST,0,0,Screen.Width\Screen.TwipsPerPixelX,Screen.Height\Screen.TwipsPerPixelY,SWP_SHOWWINDOW
EndSub
调用模块如下
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
OptionExplicit
OptionBase0
PublicDeclareFunctionSetWindowPosLib"USER32"(ByValhWndAsLong,ByValhWndInsertAfterAsLong,ByValxAsLong,ByValyAsLong,ByValcxAsLong,ByValcyAsLong,ByValwFlagsAsLong)AsLong
PublicConstHWND_TOPMOST=-1
PublicConstSWP_SHOWWINDOW=&H40
PublicTypePALETTEENTRY
peRedAsByte
peGreenAsByte
peBlueAsByte
peFlagsAsByte
EndType
PublicTypeLOGPALETTE
palVersionAsInteger
palNumEntriesAsInteger
palPalEntry(255)AsPALETTEENTRY'Enoughfor256colors.
EndType
PublicTypeGUID
Data1AsLong
Data2AsInteger
Data3AsInteger
Data4(7)AsByte
EndType
PublicConstRASTERCAPSAsLong=38
PublicConstRC_PALETTEAsLong=&H100
PublicConstSIZEPALETTEAsLong=104
PublicDeclareFunctionCreateCompatibleDCLib"GDI32"(ByValhDCAsLong)AsLong
PublicDeclareFunctionCreateCompatibleBitmapLib"GDI32"(ByValhDCAsLong,ByValnWidthAsLong,ByValnHeightAsLong)AsLong
PublicDeclareFunctionGetDeviceCapsLib"GDI32"(ByValhDCAsLong,ByValiCapabilitiyAsLong)AsLong
PublicDeclareFunctionGetSystemPaletteEntriesLib"GDI32"(ByValhDCAsLong,ByValwStartIndexAsLong,ByValwNumEntriesAsLong,lpPaletteEntriesAsPALETTEENTRY)AsLong
PublicDeclareFunctionCreatePaletteLib"GDI32"(lpLogPaletteAsLOGPALETTE)AsLong
PublicDeclareFunctionSelectObjectLib"GDI32"(ByValhDCAsLong,ByValhObjectAsLong)AsLong
PublicDeclareFunctionBitBltLib"GDI32"(ByValhDCDestAsLong,ByValXDestAsLong,ByValYDestAsLong,ByValnWidthAsLong,ByValnHeightAsLong,ByValhDCSrcAsLong,ByValXSrcAsLong,ByValYSrcAsLong,ByValdwRopAsLong)AsLong
PublicDeclareFunctionDeleteDCLib"GDI32"(ByValhDCAsLong)AsLong
PublicDeclareFunctionSelectPaletteLib"GDI32"(ByValhDCAsLong,ByValhPaletteAsLong,ByValbForceBackgroundAsLong)AsLong
PublicDeclareFunctionRealizePaletteLib"GDI32"(ByValhDCAsLong)AsLong
PublicDeclareFunctionGetWindowDCLib"USER32"(ByValhWndAsLong)AsLong
PublicDeclareFunctionGetDCLib"USER32"(ByValhWndAsLong)AsLong
PublicDeclareFunctionReleaseDCLib"USER32"(ByValhWndAsLong,ByValhDCAsLong)AsLong
PublicDeclareFunctionGetDesktopWindowLib"USER32"()AsLong
PublicTypePicBmp
SizeAsLong
TypeAsLong
hBmpAsLong