我要加入 登录
声振论坛 返回首页

gladstone的个人空间 http://home.vibunion.com/?69702 [收藏] [复制] [分享] [RSS]

日志

正弦信号的变频算法的一个例子

已有 725 次阅读2007-7-30 23:13 |个人分类:工程实例

我的《正弦信号的变频算法》的帖子,谢谢各位大侠关心,我通过今天努力,做出了一个模拟器,传上来图片供大家商祺。只能传图片,模拟器可以向我所要。gladstone510@126.com

还有如下问题需要解决:

1.如何估测源信号中50hz正弦信号的振幅和初相位?

2.是否可以一起去白噪音?有何措施?

欢迎讨论

发表评论 评论 (1 个评论)

回复 gladstone 2007-7-31 10:19
Dim K As Long, N As Long Dim Ni() As Single '信号源序列 Dim Xz() As Single '信号修正序列 Dim Xs() As Single, Xx() As Single '傅立叶变换序列fft ,Xs是实部,Xx是虚部。 Dim Xns() As Single, Xnx() As Single '傅立叶逆变换序列ifft,Xns是实部,Xnx是虚部。 Dim Nimax As Single, Nimin As Single, Xnmax As Single, Xnmin As Single Private Sub NiInit() '{Ni()}序列初始化,即信号源序列 For i = 1 To K If Option1.Value = True Then Ni(i) = Sin((2 * 3.1415926 * 50) / N * i) '{Ni}为50hz正弦函数离散序列 Randomize Ni(i) = Ni(i) + Text3 - 2 * Val(Text3) * Rnd '将rnd代换为Sqr(-2 * (Log(Rnd))) * Cos(2 * 3.1415926 * Rnd)后加的是正态噪音 If i = 1 Then Nimax = Ni(i) Nimin = Ni(i) Else If Nimax < Ni(i) Then Nimax = Ni(i) If Nimin > Ni(i) Then Nimin = Ni(i) End If Else Ni(i) = Sin((2 * 3.1415926 * 50) / N * i) + Sin((2 * 3.1415926 * 120) / N * i) '{Ni}为50hz正弦函数离散序列 Randomize Ni(i) = Ni(i) + Text3 - 2 * Val(Text3) * Rnd '将rnd代换为Sqr(-2 * (Log(Rnd))) * Cos(2 * 3.1415926 * Rnd)后加的是正态噪音 If i = 1 Then Nimax = Ni(i) Nimin = Ni(i) Else If Nimax < Ni(i) Then Nimax = Ni(i) If Nimin > Ni(i) Then Nimin = Ni(i) End If End If Next End Sub Private Sub XzInit() '修正50hz为60hz信号 For i = 1 To K Xz(i) = Sin((2 * 3.1415926 * 60) / N * i) - Sin((2 * 3.1415926 * 50) / N * i) Next End Sub Private Sub XInit() For t = 1 To K Xs(t) = 0 Xx(t) = 0 For i = 1 To K Xs(t) = Xs(t) + Ni(i) * Cos(2 * 3.1415926 * (t - 1) * (i - 1) / K) Xx(t) = Xx(t) - Ni(i) * Sin(2 * 3.1415926 * (t - 1) * (i - 1) / K) Next Next For t = 1 To K For i = 1 To K Xs(t) = Xs(t) + Xz(i) * Cos(2 * 3.1415926 * (t - 1) * (i - 1) / K) Xx(t) = Xx(t) - Xz(i) * Sin(2 * 3.1415926 * (t - 1) * (i - 1) / K) Next Next End Sub Private Sub XnInit() For i = 1 To K Xns(i) = 0 Xnx(i) = 0 For t = 1 To K Xns(i) = Xns(i) + Xs(t) * Cos(2 * 3.1415926 * (t - 1) * (i - 1) / K) - Xx(t) * Sin(2 * 3.1415926 * (t - 1) * (i - 1) / K) Xnx(i) = Xnx(i) + Xs(t) * Sin(2 * 3.1415926 * (t - 1) * (i - 1) / K) + Xx(t) * Cos(2 * 3.1415926 * (t - 1) * (i - 1) / K) Next Xns(i) = Xns(i) / K If i = 1 Then Xnmax = Xns(i) Xnmin = Xns(i) Else If Xnmax < Xns(i) Then Xnmax = Xns(i) If Xnmin > Xns(i) Then Xnmin = Xns(i) End If Next End Sub Private Sub Com_bp_Click() XzInit XInit XnInit If Nimax < 0 Then Nimax = 0 Else Nimax = Nimax * 1.1 End If If Nimin > 0 Then Nimin = 0 Else Nimin = Nimin * 1.1 End If Pic1.Scale (0, Nimax)-(K + 2, Nimin) Pic1.CurrentX = 1 Pic1.CurrentY = Ni(1) For i = 2 To K Pic1.Line -(i + 1, Ni(i)) Next For i = 1 To K Pic1.Circle (i + 1, Ni(i)), 0.2, vbRed Next ''''''''''''''''''''''''''''''''' If Xnmax < 0 Then Xnmax = 0 Else Xnmax = Xnmax * 1.1 End If If Xnmin > 0 Then Xnmin = 0 Else Xnmin = Xnmin * 1.1 End If Pic2.Scale (0, Xnmax)-(K + 2, Xnmin) Pic2.CurrentX = 1 Pic2.CurrentY = Xns(1) For i = 2 To K Pic2.Line -(i + 1, Xns(i)) Next For i = 1 To K Pic2.Circle (i + 1, Xns(i)), 0.2, vbRed Next End Sub Private Sub Com_csh_Click() K = Text1 N = Text2 ReDim Ni(K), Xz(K), Xs(K), Xns(K), Xx(K), Xnx(K) NiInit XzInit End Sub Private Sub Comm_cp_Click() Pic1.Cls Pic2.Cls End Sub Private Sub Form_Load() Com_csh_Click Option1.Value = True End Sub Private Sub Option1_Click() Option1.Value = True Option2.Value = False End Sub Private Sub Option2_Click() Option2.Value = True Option1.Value = False End Sub :victory:

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 我要加入

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-6 07:12 , Processed in 0.035164 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部