⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 这是一个FFT计算的visual basic例程
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   8535
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   9255
   LinkTopic       =   "Form1"
   ScaleHeight     =   8535
   ScaleWidth      =   9255
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox Text4 
      Height          =   1215
      Left            =   1320
      TabIndex        =   7
      Top             =   5760
      Width           =   7695
   End
   Begin VB.TextBox Text3 
      Height          =   1695
      Left            =   1320
      MultiLine       =   -1  'True
      TabIndex        =   2
      Text            =   "Form1.frx":0000
      Top             =   3840
      Width           =   7695
   End
   Begin VB.TextBox Text2 
      Height          =   1815
      Left            =   1320
      MultiLine       =   -1  'True
      TabIndex        =   1
      Text            =   "Form1.frx":0006
      Top             =   1680
      Width           =   7575
   End
   Begin VB.TextBox Text1 
      Height          =   1215
      Left            =   1320
      MultiLine       =   -1  'True
      TabIndex        =   0
      Text            =   "Form1.frx":000C
      Top             =   240
      Width           =   7575
   End
   Begin VB.Label Label5 
      Caption         =   "Output Argument"
      Height          =   1215
      Left            =   120
      TabIndex        =   6
      Top             =   5760
      Width           =   975
   End
   Begin VB.Label Label3 
      Caption         =   "Real Input signal while imaginary is reset =0"
      Height          =   1335
      Left            =   240
      TabIndex        =   5
      Top             =   3960
      Width           =   975
   End
   Begin VB.Label Label2 
      Caption         =   "Imaginary OP FFT"
      Height          =   855
      Left            =   240
      TabIndex        =   4
      Top             =   1920
      Width           =   975
   End
   Begin VB.Label Label1 
      Caption         =   "Real OP fft"
      Height          =   495
      Left            =   240
      TabIndex        =   3
      Top             =   480
      Width           =   855
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

'************************************************************************************'
'FFT software built by Sherif Omran as part of my master degree year 2001            '
'There are many methods to do FFT , this is the fastest, it is more faster than      '
'Matlab. all what you have to do is to edit the number of points n and edit the bse  '
'and put the fft_click sub in your program .   It really took very long time to build'
'It, It was built for the old basic under dos. and now upgraded.                     '
'I am now the reasearch and development manager of www.pcfone.com                    '
'when the form loads, it defines the funct,functI the real and imaginary part of the '
'Input signal, when you call the sub FFT_click , the output is put again in the funct'
'and functI as real output and imaginary output, you must know that you cant draw the'
'real only, this is wrong, you must draw the modulus of both sqr(real^2+imaginary^2) '
'and draw also the phase if you need it where theta=ARCTAN(imaginary/real)           '
'feel free to use the code , if you have any questions email me omran@mail.com       '
'when you use the code , mention my name in the team work.                           '
'Regards and hopes to have fun with my code.                                         '
'There is another codes at www.planet-source-code.com which can do more filters      '
'************************************************************************************'

'Dim n As Integer ' number of fft points
Const n = 256
Const bse = 8 'log(n) base 2 = log(n)/log(2)
Dim funct(n) 'input and output function real one
Dim functI(n) 'imaginary one
Dim inputR(n) As Double, inputI(n), outputR(n), outputI(n), bitrevinputR(n * 2), bitrevinputI(2 * n)
Dim a(2 * n): Dim ax(2 * n): Dim taken(2 * n): Dim aI(2 * n)
Dim r(bse + 1), b(bse + 1), expon(n / 2, n / 2), m(bse), erf(bse), noftwf(bse), twfexp(n / 2, n / 2)

Private Sub FFT_Click()
'ReDim inputR(16)


Text1.Text = "": Text2.Text = ""
c = Log(n) / Log(2):
Dim i As Integer

'detect twiddle factor
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'twiddle factor exponent generation part
'c represents the number of states
For i = 1 To c: m(i) = i: erf(i) = 2 ^ ((c) - i)
noftwf(i) = 2 ^ (m(i) - 1)
Next
'rem defining the twf exponent in a square array of
'inputs equal to the last no of twfs which is noftwf(c) will be in sq
sq = noftwf(c)
twfexp(0, 0) = 0
'initializing the square matrix by equaling it to zero
For t = 1 To c: For x = 1 To sq: twfexp(x, t) = 0: Next: Next
'finished initializing the matrix
For t = 1 To c
For x = 1 To noftwf(t)
If x = 1 Then twfexp(x, t) = 0: GoTo nn
twfexp(x, t) = twfexp(x - 1, t) + erf(t)
nn:
Next: Next
'now we are going to define a new matrix representing the exponent
'value of the Twf which will be used in the multiplication of two
'terms
Height1 = noftwf(t - 1) 'this is the height of the matrix
wide = c 'this is the width of the matrix

For stage = 1 To Log(n) / Log(2)
Item = 1
For y = 1 To Height1
x = twfexp(Item, stage)
expon(y, stage) = x
Item = Item + 1
If Item = noftwf(stage) + 1 Then Item = 1
Next: Next
'the twiddle factors exponent is in expon(height,width)
'''''''''''''''''''''''''''''''''''''''

'input signal to fft sub
Text3.Text = ""
For i = 0 To n - 1: inputR(i) = funct(i):
inputI(i) = functI(i):

Text3.Text = Text3.Text + Str$(inputR(i))
Next

'Bit reversal arrangment
For t = 0 To n - 1
e = t
hh = Log(n) / Log(2) - 1

For i = hh To 0 Step -1
u = 2 ^ i
If e >= u Then r(i) = 1: e = e - u Else r(i) = 0
'bitreversing the binary sequence
b(hh - i) = r(i)
Next

ax1 = 0
For isf = hh To 0 Step -1
ax1 = ax1 + b(isf) * 2 ^ (isf)
Next
ax(t) = ax1
Next t
stages = Log(n) / Log(2)

'arranging the output values into bitreversal sort
For dd = 0 To n - 1
bitrevinputR(dd) = inputR(ax(dd)): bitrevinputI(ax(dd)) = inputI(dd)
Next dd
'the input is bit reversed and found in bitrevinputR(x)
For y = 0 To n - 1: taken(y) = 0:
Next: x = 0: t = 0: y = 0: i = 0

c = Log(n) / Log(2)
'imaginary input data=0
For xx = 0 To n - 1: bitrevinputI(xx) = 0: Next
For i = 0 To n - 1
Next: ' CLS
jump = 1: half = n / 2
st = 0
bitrevinputR(n) = 0: bitrevinputR(n + 1) = 0
bitrevinputI(n) = 0: bitrevinputI(n + 1) = 0
For u = 1 To Log(n) / Log(2): st = 0
For i = 0 To n - 1
10
For t = 0 To x - 1
If i = taken(t) Then t = x - 1: GoTo 12
Next t
st = st + 1
twfr = Cos(-1 * 2 * 3.14 * expon(st, u) / n):
twfi = Sin(-1 * 2 * 3.14 * expon(st, u) / n):
a(i) = bitrevinputR(i) + bitrevinputR(i + jump) * (twfr) - bitrevinputI(i + jump) * twfi
aI(i) = bitrevinputI(i) + bitrevinputR(i + jump) * (twfi) + bitrevinputI(i + jump) * (twfr)
a(i + jump) = bitrevinputR(i) - bitrevinputR(i + jump) * (twfr) + bitrevinputI(i + jump) * twfi
aI(i + jump) = bitrevinputI(i) - bitrevinputR(i + jump) * (twfi) - bitrevinputI(i + jump) * (twfr)
taken(x) = i + jump: x = x + 1
12
Next
'For d = 0 To n - 1: Print a(d); aI(d): Next
jump = 2 ^ (u)
For y = 0 To n - 1: taken(y) = 0:
bitrevinputR(y) = a(y): bitrevinputI(y) = aI(y)
Next: x = 0: t = 0
i = 0
Next u

For y = 0 To n - 1
funct(y) = bitrevinputR(y)
functI(y) = bitrevinputI(y)
Next

Text1.Text = "DATA OUTPUT ---- The wave Signal present in memory" + String$(55, " ")
Text1.Text = Text1.Text + "X(n) REAL" + String$(128, " ")
For i = 0 To n - 1: Text1.Text = Text1.Text + Str$(funct(i)) + "   "
Next:
Text1.Text = Text1.Text
Text2.Text = Text2.Text + "X(n) Imaginary" + String$(122, " ") + kbkeyreturn
For i = 0 To n - 1
Text2.Text = Text2.Text + Str$(functI(i)) & "    "
Next

Exit Sub

End Sub

Private Sub getmodulus()
Dim argument(n), theta(n)
For i = 0 To n
argument(i) = Sqr((funct(i)) ^ 2 + (functI(i)) ^ 2)
Text4.Text = Text4.Text & argument(i) & "   "
'theta(i) = ArcTAN(functI(i) / funct(i))
Next
End Sub

Private Sub Form_Load()
'n = 16
'step function
For i = 0 To n / 2: funct(i) = 1: Next
For i = n / 2 To n - 1: funct(i) = 0: Next
FFT_Click
getmodulus ' to get the moduls which you can draw if needed

End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -