Imports System.Math
Public Class WindowFunctions
' Fourier frame size
Private N As Integer
' single precision
Private ws() As Single = Nothing
' double precision
Private wd() As Double = Nothing
Enum wfType
Hanning
Hamming
Blackman
Nuttall
BlackmanNuttall
BlackmanHarris
FlatTop
End Enum
Public Sub New(ByVal Nval As Integer, ByVal t As wfType)
N = Nval
Dim coef() As Double = Nothing
Select Case t
Case wfType.Hanning
coef = New Double() {0.5, 0.5}
Case wfType.Hamming
coef = New Double() {0.54, -0.46}
Case wfType.Blackman
coef = New Double() {7938 / 18608, 9240 / 18608, 1430 / 18608}
Case wfType.Nuttall
coef = New Double() {0.355768, 0.487396, 0.144232, 0.012604}
Case wfType.BlackmanNuttall
coef = New Double() {0.3635819, 0.4891775, 0.1365995, 0.0106411}
Case wfType.BlackmanHarris
coef = New Double() {0.35875, 0.48829, 0.14128, 0.01168}
Case wfType.FlatTop
End Select
ReDim wd(N - 1)
ReDim ws(N - 1)
For i As Integer = 0 To N - 1
Dim sum As Double = 0
For j As Integer = 0 To coef.Length - 1
sum += 1.73 * coef(j) * Cos(2 * PI * j * (i - N \ 2) / N)
Next
wd(i) = sum
ws(i) = CSng(sum)
Next
End Sub
'''
''' Over
'''
'''
'''
'''
''' Overwrites the variable y.
Public Shared Operator *(ByVal x As WindowFunctions, ByVal y() As Double) As Double()
For j As Integer = 0 To x.N - 1
y(j) *= x.wd(j)
Next
Return y
End Operator
'''
''' Over
'''
'''
'''
'''
''' Overwrites the variable y.
Public Shared Operator *(ByVal x As WindowFunctions, ByVal y() As Single) As Single()
For j As Integer = 0 To x.N - 1
y(j) *= x.ws(j)
Next
Return y
End Operator
'''
''' Over
'''
'''
''' Overwrites the variable y.
Public Overloads Sub mult2(ByVal y() As Double)
For j As Integer = 0 To N - 1
Dim j2 As Integer = j << 1
y(j2) *= wd(j)
y(j2 Or 1) *= wd(j)
Next
End Sub
'''
''' Over
'''
'''
''' Overwrites the variable y.
Public Overloads Sub mult2(ByVal y() As Single)
For j As Integer = 0 To N - 1
Dim j2 As Integer = j << 1
y(j2) *= ws(j)
y(j2 Or 1) *= ws(j)
Next
End Sub
End Class