博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#实现一维小波变换
阅读量:7192 次
发布时间:2019-06-29

本文共 1962 字,大约阅读时间需要 6 分钟。

hot3.png

 //小波变换函数
private void mwavelet1D(double[] scl0,double[] p,double[] q,out double[]  scl1,out double[] wvl1)
        {
            int temp = 0;
            int scllen = scl0.Length;
            int plen = p.Length;
            scl1=new double[scllen/2];
            wvl1=new double[scllen/2];
            for (int i = 0; i < scllen / 2;i++ )
            {
                scl1[i] = 0;
                wvl1[i] = 0;
                for (int j = 0; j < plen;++j )
                {
                    temp = (j + i * 2) % scllen;
                    scl1[i]+=p[j]*scl0[temp];
                    wvl1[i]+=q[j]*scl0[temp];
                }
            }
        }
        
        private void button2_Click(object sender, EventArgs e)
        {
        //低通滤波器
            double[] lowFilter = new double[] { 0.48296291314453, 0.83651630373780, 0.22414386804201, -0.12940952255126 };
        //高通滤波器
            double[] highFilter = new double[lowFilter.Length];
            for (int i = 0; i < lowFilter.Length;++i )
            {
                highFilter[i]=Math.Pow(-1,i)*lowFilter[lowFilter.Length-1-i];
            }
        //测试数据
            double[] src = new double[] { 0, 2, 4, 8, 16, 32, 64, 128, 64, 32, 16, 8, 4, 2, 0, 0, 2, 4, 8, 16, 32, 64, 128, 64, 32, 16, 8, 4, 2, 0, 0, 2, 4, 8, 16, 32, 64, 128, 64, 32, 16, 8, 4, 2, 0, 0, 2, 4, 8, 16, 32, 64, 128, 64, 32, 16, 8, 4, 2, 0, 0, 2, 4, 8, 16, 32, 64, 128, 64, 32, 16, 8, 4, 2, 0, 0, 2, 4, 8, 16, 32, 64, 128, 64, 32, 16, 8, 4, 2, 0 };
            double[] dst1=null;
            double[] dst2=null;
            mwavelet1D(src, lowFilter, highFilter, out dst1,out dst2);
            Graphics g = Graphics.FromHwnd(pictureBox1.Handle);
            Pen pen = Pens.Blue;
            Pen pen2 = Pens.Red;
            Pen pen3= Pens.Green;
        //画出原始数据
            for (int i = 0; i < src.Length-1;++i )
            {
                Point p1=new Point(i*10+10,(int)(src[i]));
                Point p2=new Point((i+1)*10+10,(int)(src[i+1]));
                g.DrawLine(pen,p1,p2);
            }
        //画出低频分量
            for (int i = 0; i < dst1.Length - 1; ++i)
            {
                Point p1 = new Point(i*10 + 10, 200+(int)(dst1[i] ));
                Point p2 = new Point((i+1)*10 + 10, 200+(int)(dst1[i + 1] ));
                g.DrawLine(pen2, p1, p2);
            }
        //画出高频分量
            for (int i = 0; i < dst2.Length - 1; ++i)
            {
                Point p1 = new Point(i * 10 + 500, 200 + (int)(dst2[i] ));
                Point p2 = new Point((i + 1) * 10 + 500, 200 + (int)(dst2[i + 1] ));
                g.DrawLine(pen3, p1, p2);
            }

        }

最后效果图如下:

转载于:https://my.oschina.net/jingshishengxu/blog/132996

你可能感兴趣的文章
"ApplicationDbContext"(泛指之类的数据库上下文模型)上下文的模型已在数据库创建后发生更改。请考虑使用 Code First 迁移更新数据库。...
查看>>
Django Model 基础数据库操作应用
查看>>
Java ConcurrentModificationException异常原因和解决方法[转载]
查看>>
单例模式防止反射和反序列化
查看>>
聚集索引和非聚集索引的区别
查看>>
搭建前端监控系统(备选)用户行为统计和监控篇(如何快速定位线上问题)...
查看>>
linux常用命令
查看>>
jQuery remove与detach的区别
查看>>
openstack镜像服务(glance)
查看>>
Dictionary字典类关联数组
查看>>
迭代器及生成器
查看>>
[20171107]dbms_shared_pool.pin.txt
查看>>
UIView
查看>>
mysql-distinct去重、mysql-group&nbsp;…
查看>>
Vmworkstation启用错误
查看>>
mysql中函数DISTINCT,group by,CONCAT及GROUP_CONCAT的使用
查看>>
4月5日 编码问题
查看>>
消息反射
查看>>
DVWA之brute force
查看>>
HTML DOM 第一篇
查看>>