请教低通数字滤波器
请教滤波器 我用的是正弦窗FIR滤波器。原信号是在0.5Hz正弦信号基础上叠加随机噪声得到的,下面是相关的程序,最后图中展示了“滤波前”。 滤波后为什么顶被削平了呢?我只想去掉高频噪声啊?高人指点应该怎么做,或者有什么不对的地方,谢谢!!!首先生成基本的0.5Hz正弦信号:
Private Sub CommandButton1_Click()
Dim I As Integer
Dim X As Double
X = 0#
For I = 1 To 1000
Cells(I, 1) = VBA.Sin(1 * 3.14159 * X)'原始信号周期T=2s原始信号频率Fs=0.5Hz 采样频率为50Hz
X = X + 0.02 '0.02秒采集一个数据采样频率=50Hz
Next I
End Sub
然后给基本信号加随机噪声:
Private Sub CommandButton2_Click()
For I = 1 To 1000
Cells(I, 2) = Cells(I, 1) + 0.4 * Rnd - 0.2
Next I
End Sub
最后设计滤波器并滤波:
Public Sub FilterSinc()
'低通 WINDOWED-SINC FIR滤波器
'This program filters 1000 samples with a 33 point windowed-sinc
'filter, resulting in 900 samples of filtered data.
'
' 'INITIALIZE AND DEFINE THE ARRAYS USED
Dim X(0 To 999) As Long 'X( ) holds the input signal
Dim Y(0 To 999) As Long 'Y( ) holds the output signal
Dim H(0 to 32) As Double 'H( ) holds the filter kernel
'
Dim Pi As Double
Dim FC As Double
Dim M, I, J As Integer
Pi = 3.14159265
FC =2 '截止频率 2Hz
M = 32 '滤波器的核,即阶数
'加载数据
For I = 0 To 999
X(I) = Cells(I + 1, 2)
Next I
I = 0
' '
'计算滤波器的核
For I = 0 To 32
If (I - M / 2) = 0 Then H(I) = 2 * Pi * FC
If (I - M / 2) <> 0 Then H(I) = Sin(2 * Pi * FC * (I - M / 2)) / (I - M / 2)
H(I) = H(I) * (0.54 - 0.46 * Cos(2 * Pi * I / M))
Next I
'
'卷积滤波
For J = 32 To 999
Y(J) = 0
For I = 0 To 32
Y(J) = Y(J) + X(J - I) * H(I)
Next I
Cells(J, 3) = Y(J)
Next J
End Sub
期待高人点化~~~
跪请高人指点,等一晚上了,呵呵 期待高人现身 ~~~~ 我苦苦等了4年啊,大哥啊大哥,出来说说吧
页:
[1]