2019独角兽企业重金招聘Python工程师标准>>>

头文件:

/** Copyright (c) 2008-2011 Zhang Ming (M. Zhang), zmjerry@163.com** This program is free software; you can redistribute it and/or modify it* under the terms of the GNU General Public License as published by the* Free Software Foundation, either version 2 or any later version.** Redistribution and use in source and binary forms, with or without* modification, are permitted provided that the following conditions are met:** 1. Redistributions of source code must retain the above copyright notice,*    this list of conditions and the following disclaimer.** 2. Redistributions in binary form must reproduce the above copyright*    notice, this list of conditions and the following disclaimer in the*    documentation and/or other materials provided with the distribution.** This program is distributed in the hope that it will be useful, but WITHOUT* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for* more details. A copy of the GNU General Public License is available at:* http://www.fsf.org/licensing/licenses*//******************************************************************************                                    wvd.h** Wigner-Ville distribution of one dimension signal "sn".** The "sn" can be either real signal or complex signal. The WVD coefficients* is an N-by-N REAL matrix, where N is the signal length.** Zhang Ming, 2010-10, Xi'an Jiaotong University.*****************************************************************************/#ifndef WVD_H
#define WVD_H#include <vector.h>
#include <matrix.h>
#include <fft.h>
#include <vectormath.h>
#include <utilities.h>namespace splab
{template<typename Type> Matrix<Type> wvd( const Vector<Type>& );template<typename Type> Matrix<Type> wvd( const Vector< complex<Type> >& );#include <wvd-impl.h>}
// namespace splab#endif
// WVD_H

实现文件:

/** Copyright (c) 2008-2011 Zhang Ming (M. Zhang), zmjerry@163.com** This program is free software; you can redistribute it and/or modify it* under the terms of the GNU General Public License as published by the* Free Software Foundation, either version 2 or any later version.** Redistribution and use in source and binary forms, with or without* modification, are permitted provided that the following conditions are met:** 1. Redistributions of source code must retain the above copyright notice,*    this list of conditions and the following disclaimer.** 2. Redistributions in binary form must reproduce the above copyright*    notice, this list of conditions and the following disclaimer in the*    documentation and/or other materials provided with the distribution.** This program is distributed in the hope that it will be useful, but WITHOUT* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for* more details. A copy of the GNU General Public License is available at:* http://www.fsf.org/licensing/licenses*//******************************************************************************                                wvd-impl.h** Implementation for Wigner-Ville distribution.** Zhang Ming, 2010-10, Xi'an Jiaotong University.*****************************************************************************//*** Compute WVD of 1D real signal "sn". The WVD coeffitions are stored* in "coefs", a complex matrix. The column represents time, and row* represents frequency.*/
template <typename Type>
Matrix<Type> wvd( const Vector<Type> &sn )
{int N = sn.size(),dN = 2*N;Vector<Type> xn = fftInterp( sn, 2 );Vector<Type> fn( 3*dN );for( int i=dN; i<2*dN; ++i )fn[i] = xn[i-dN];Vector<Type> yn( dN );Matrix<Type> coefs( N, N );for( int n=1; n<=N; ++n ){for( int i=0; i<N; ++i )yn[i] = fn(dN+2*n+i) * fn(dN+2*n-i);for( int i=-N; i<0; ++i )yn[dN+i] = fn(dN+2*n+i) * fn(dN+2*n-i);coefs.setColumn( dyadDown(real(fft(yn)),0), n-1 );}return coefs;
}/*** Compute WVD of 1D complex signal "cn". The WVD coeffitions are stored* in "coefs", a complex matrix. The column represents time, and row* represents frequency.*/
template <typename Type>
Matrix<Type> wvd( const Vector< complex<Type> > &cn )
{int N = cn.size(),dN = 2*N;Vector< complex<Type> > xn = fftInterp( cn, 2 );Vector< complex<Type> > fn(3*dN);for( int i=dN; i<2*dN; ++i )fn[i] = xn[i-dN];Vector< complex<Type> > yn( dN );Matrix<Type> coefs( N, N );for( int n=1; n<=N; ++n ){for( int i=0; i<N; ++i )yn[i] = fn(dN+2*n+i) * conj(fn(dN+2*n-i));for( int i=-N; i<0; ++i )yn[dN+i] = fn(dN+2*n+i) * conj(fn(dN+2*n-i));coefs.setColumn( dyadDown(real(fft(yn)),0), n-1 );}return coefs;
}

测试代码:

/******************************************************************************                               wvd_test.cpp** Wigner-Ville distribution testing.** Zhang Ming, 2010-10, Xi'an Jiaotong University.*****************************************************************************/#define BOUNDS_CHECK#include <iostream>
#include <iomanip>
#include <timing.h>
#include <wvd.h>using namespace std;
using namespace splab;typedef double  Type;
const   int     Ls = 100;int main()
{/******************************* [ signal ] ******************************/Vector<Type> t = linspace( Type(-0.5), Type(0.5-1.0/Ls), Ls );Vector< complex<Type> > sn(Ls);for( int i=0; i<Ls; ++i ){Type tip2 = t[i]*t[i],freq = Type(TWOPI*25);sn[i] = exp(-32*tip2) * polar(Type(1),freq*t[i]) * polar(Type(1),freq*tip2);}cout << setiosflags(ios::fixed) << setprecision(4);/********************************* [ WVD ] *******************************/Type runtime = 0;Timing cnt;cout << "Computing Wigner-Wille distribution." << endl << endl;cnt.start();Matrix<Type> coefs = wvd( sn );cnt.stop();runtime = cnt.read();cout << "The running time = " << runtime << " (ms)" << endl << endl;Vector<Type> timeMarg = mean(coefs),freqMarg = mean(trT(coefs));cout << "The time marginal condition is: " << timeMarg << endl;cout << "The frequency marginal condition is: " << freqMarg << endl;return 0;
}

运行结果:

Computing Wigner-Wille distribution.The running time = 0.0150 (ms)The time marginal condition is: size: 100 by 1
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0001
0.0001
0.0002
0.0003
0.0005
0.0008
0.0012
0.0017
0.0026
0.0038
0.0055
0.0079
0.0112
0.0156
0.0214
0.0292
0.0392
0.0519
0.0679
0.0877
0.1118
0.1409
0.1751
0.2148
0.2604
0.3115
0.3678
0.4290
0.4938
0.5612
0.6298
0.6978
0.7630
0.8239
0.8785
0.9246
0.9607
0.9857
0.9985
0.9984
0.9856
0.9608
0.9247
0.8784
0.8239
0.7630
0.6978
0.6298
0.5612
0.4937
0.4290
0.3679
0.3115
0.2604
0.2148
0.1751
0.1409
0.1119
0.0877
0.0679
0.0519
0.0391
0.0292
0.0215
0.0156
0.0112
0.0079
0.0055
0.0038
0.0026
0.0017
0.0012
0.0008
0.0005
0.0003
0.0002
0.0001
0.0001
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000The frequency marginal condition is: size: 100 by 1
0.0000
0.0000
0.0000
0.0000
0.0000
0.0001
0.0003
0.0007
0.0016
0.0036
0.0078
0.0158
0.0308
0.0569
0.1001
0.1678
0.2677
0.4064
0.5877
0.8089
1.0600
1.3226
1.5707
1.7763
1.9121
1.9598
1.9121
1.7763
1.5707
1.3226
1.0600
0.8089
0.5877
0.4064
0.2677
0.1678
0.1001
0.0569
0.0308
0.0158
0.0078
0.0036
0.0016
0.0007
0.0003
0.0001
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000Process returned 0 (0x0)   execution time : 0.203 s
Press any key to continue.

转载于:https://my.oschina.net/zmjerry/blog/8487

Wigner-Ville分布算法的C++实现相关推荐

  1. python所有算法_Python实现的各种常见分布算法示例

    本文实例讲述了Python实现的各种常见分布算法.分享给大家供大家参考,具体如下: #-*- encoding:utf-8 -*- import numpy as np from scipy impo ...

  2. memcached客户端(分布算法)

    一.背景资料 memcached本身是集中式的缓存系统,要搞多节点分布,只能通过客户端实现.memcached的分布算法一般有两种选择: 1.根据hash(key)的结果,模连接数的余数决定存储到哪个 ...

  3. python求伽马分布模型参数_Python实现的各种常见分布算法示例

    本文实例讲述了Python实现的各种常见分布算法.分享给大家供大家参考,具体如下: #-*- encoding:utf-8 -*- import numpy as np from scipy impo ...

  4. matlab 图像平滑的算法_图像相似度---灰度分布算法---用matlab实现

    基于matlab2020b,不同版本可能会出错 步骤: 读取图片数据(相当于一个矩阵) 匹配两张图片的尺寸 用imhist函数画出灰度分布图 将灰度分布图归一化 计算巴氏距离得到相似度 代码实现: c ...

  5. 分布的matlab实现_图像相似度---灰度分布算法---用matlab实现

    基于matlab2020b,不同版本可能会出错 步骤: 读取图片数据(相当于一个矩阵) 匹配两张图片的尺寸 用imhist函数画出灰度分布图 将灰度分布图归一化 计算巴氏距离得到相似度 代码实现: c ...

  6. 时频分析方法总结:傅里叶级数及傅里叶变换、STFT 、小波变换、Wigner-Ville 分布

    前言: 一.傅里叶变换的机理 一个能量无限的正弦信号和源信号乘积并求和得到某个频率下的系数,随着频率的增加,正弦信号改变,再次求得系数,依次构成了频谱图 傅里叶级数及傅里叶变换 https://blo ...

  7. 最常用的决策树算法!Random Forest、Adaboost、GBDT 算法

    点击上方"Datawhale",选择"星标"公众号 第一时间获取价值内容 本文主要介绍基于集成学习的决策树,其主要通过不同学习框架生产基学习器,并综合所有基学习 ...

  8. gbdt 算法比随机森林容易_机器学习(七)——Adaboost和梯度提升树GBDT

    1.Adaboost算法原理,优缺点: 理论上任何学习器都可以用于Adaboost.但一般来说,使用最广泛的Adaboost弱学习器是决策树和神经网络.对于决策树,Adaboost分类用了CART分类 ...

  9. memcached 分布式 一致性hash算法demo

    一致性Hash分布算法分4个步骤: 步骤1:将一个32位整数[0 ~ (2^32-1)]想象成一个环,0 作为开头,(2^32-1) 作为结尾,当然这只是想象. 步骤2:通过Hash函数把KEY处理成 ...

最新文章

  1. 毕业设计记录(二)配置mysql5.0数据库的问题
  2. 如何最小化云API升级造成的中断?
  3. php获取longtext字段为空,php – 在longtext字段上准备好的mysqli select语句将返回空...
  4. MSSQL的多层嵌套查询
  5. Android开发--真机调试出现device offline提示
  6. jquery调用WCF
  7. Redis 安装与配置
  8. Linux(debian7)操作基础(三)之PCI/PCI-E设备配置空间
  9. Spring 系列: Spring 框架
  10. python调用指定浏览器打开网页
  11. 如何在多次触发事件时只执行一次?(函数防抖)
  12. android开发 自我优势_android开发简历自我评价填写样本
  13. 伍德里奇计量经济学导论pdf_伍德里奇 计量经济学导论(第六版) 第3章
  14. 微信企业号开发七:JSAPI模式
  15. 从致敬KAWS系列盲盒大火,看“NFT+盲盒”玩法的想象空间
  16. 动物识别Python
  17. Redis看这一篇就够了
  18. 清华大学赵明国:AI芯片 +机器人,突破算法瓶颈
  19. Unity MVC框架之见解
  20. C语言 编写登录系统

热门文章

  1. Apache VFS:基本介绍
  2. Python基础-XML模块
  3. Print out Android kernel log
  4. 百战程序员试题与答案(仅供参考)
  5. 从零开始学android开发-IDE空间不够报错
  6. SharePoint服务器修改域和机器名
  7. C#事件-自定义事件
  8. Android WebView 开发详解(一)
  9. Android ListView侧滑item,仿QQ删除效果
  10. 2014025689《嵌入式程序设计》第一周学习总结