最近在研究信号处理的C语言算法,突然发现一个西安交大的师兄之前已经写出来了一个完整的库,同样是研究生三年,差别怎么这样大呢。

先从用轮子开始吧。

一、SP++3.0安装及测试

官网下载地址:

https://code.google.com/archive/p/tspl/downloads

将 SP++3.0 压缩包解压到某一路径下,如 D:\Program Files\SP++3.0

建立VS2010 项目,在Project->Propertiesr的VC++Directories->Include Directories
中加入D:\Program Files\SP++3.0\include

然后添加一个fft_test.cpp,进行测试

/*****************************************************************************
* fft_test.cpp
*
* FFT test.
*
* Zhang Ming, 2010-09, Xi'an Jiaotong University.
*****************************************************************************/ #include <iostream>
#include <cstdlib>
#include <vectormath.h>
#include <fft.h> using namespace std;
using namespace splab; typedef double Type;
const int MINLEN = 1;
const int MAXLEN = 1000;
const int STEP = 10; int main()
{
Vector< complex<Type> > sn, Rk, Sk, xn;
Vector<Type> rn, tn; cout << "forward transform: complex to complex." << endl;
cout << "inverse transform: complex to complex." << endl << endl;
cout << "signal length" << "\t" << "mean(abs((sn-xn))" << endl;
for( int len=MINLEN; len<MAXLEN; len+=STEP )
{
sn.resize(len);
for( int i=0; i<len; ++i )
sn[i] = complex<Type>( rand()%10, rand()%10 ); Sk = fftc2c( sn );
xn = ifftc2c( Sk );
// Sk = fft( sn );
// xn = ifft( Sk );
cout << " " << len << "\t\t" << " " << sum(abs(sn-xn))/len << endl;
}
cout << endl << endl; cout << "forward transform: real to complex ." << endl;
cout << "inverse transform: complex to real." << endl << endl;
cout << "signal length" << "\t" << "mean(abs((rn-tn))" << endl;
for( int len=MINLEN; len<MAXLEN; len+=STEP )
{
rn.resize(len);
for( int i=0; i<len; ++i )
rn[i] = rand()%10; Rk = fftr2c( rn );
tn = ifftc2r( Rk );
// Rk = fft( rn );
// tn = real( ifft(Rk) );
cout << " " << len << "\t\t" << " " << sum(abs(rn-tn))/len << endl;
}
cout << endl; return 0;
}

  

编译会产生错误:min,max出现在未命名空间,直接注释即可(也可在主文件添加#inlucde<algorthm>)。

之后编译成功。

、SP++3.0测试含matlab plot代码

注意:

此处必须先加载SP++3.0\include,然后再加载Matalb\extern\inlcude,因为SP++3.0 与Matlab中都有matrix.h头文件,如果加载顺序相反,则无法通过编译;

此处配置Matlab环境,参考文章:https://www.cnblogs.com/shuqingstudy/p/10134254.html

配置完成后,测试cppmatlab_test.cpp

/*****************************************************************************
* CppMatlab_test.cpp
*
* C++ and Matlab mixed programming testing.
*
* Zhang Ming, 2010-10, Xi'an Jiaotong University.
*****************************************************************************/ #define BOUNDS_CHECK #include <iostream>
#include <cstring>
#include <vectormath.h>
#include <matrixmath.h>
#include <wft.h>
#include "engine.h" using namespace std;
using namespace splab; typedef double Type;
const int Lg = 128;
const int Ls = 1000;
const Type Fs = 1000; int main()
{
/******************************* [ signal ] ******************************/
Vector<Type> t = linspace( Type(0), Type(Ls-1), Ls ) / Type(Fs);
Vector<Type> s = sin( Type(400*PI) * pow(t,Type(2.0)) ); /******************************** [ widow ] ******************************/
t = linspace(Type(0),Type(Lg-1),Lg);
Vector<Type> g = gauss( t, (Lg-1)/Type(2), Lg/Type(8) ); /********************************* [ WFT ] *******************************/
cout << "Taking windowed Fourier transform." << endl;
Matrix< complex<Type> > coefs = wft( s, g ); /******************************** [ IWFT ] *******************************/
cout << "Taking inverse windowed Fourier transform." << endl;
Vector<Type> x = iwft( coefs, g ); cout << "The relative error is : " << "norm(s-x) / norm(s) = "
<< norm(s-x)/norm(s) << endl << endl; /******************************** [ PLOT ] *******************************/
Engine *ep = engOpen( NULL );
if( !ep )
{
cerr << "Cannot open Matlab Engine!" << endl;
exit(1);
} Matrix<Type> C = trT( abs(coefs) );
int M = C.rows(), N = C.cols(); // define mxArray as 1-by-1 Real Scalar
mxArray *mFs = mxCreateDoubleMatrix( 1, 1, mxREAL ); // define mxArray as N-by-1 Real Vector
mxArray *ms = mxCreateDoubleMatrix( Ls, 1, mxREAL );
mxArray *mx = mxCreateDoubleMatrix( Ls, 1, mxREAL ); // define mxArray as N-by-M Real Matrix, BECAUSE matalb is ROW MAJOR
// and C/C++ is COLUMN MAJOR, the row of SP++ matrix is copied as the
// column of Matlab matrix
mxArray *mC = mxCreateDoubleMatrix( N, M, mxREAL ); // array copy from Scalar to mxArray.
memcpy( mxGetPr(mFs), &Fs, sizeof(Type) ); // array copy from Vectors to mxArray.
memcpy( mxGetPr(ms), s, Ls*sizeof(Type) );
memcpy( mxGetPr(mx), x, Ls*sizeof(Type) ); // array copy from Matrix to mxArray.
memcpy( mxGetPr(mC), C, C.size()*sizeof(Type) ); // send command to Matlab engine
engPutVariable( ep, "fs", mFs );
engPutVariable( ep, "s", ms );
engPutVariable( ep, "x", mx );
engPutVariable( ep, "C", mC ); // Matlab commands
const char *mCmd = " \
figure('name','C++ and Matlab Mixed Programming Testing'); \
hFN = floor(size(C,1)/2); tN = size(C,2); \
subplot(2,2,1); plot((0:tN-1), s); \
axis([0,tN,min(s),max(s)]); \
xlabel('Time (ms)', 'fontsize',12); ylabel('Amplitude', 'fontsize',12); \
title('(a)'); \
subplot(2,2,2); pcolor((0:tN-1),(0:hFN)'/hFN, C(1:hFN+1,:)); \
shading interp; \
axis([0,tN, 0,1]); \
yt = 0 : 0.2 : 1; set(gca, 'YTick',yt); set(gca, 'YTickLabel',fs*yt/2); \
xlabel('Time (ms)','fontsize',12); ylabel('Frequency (Hz)','fontsize',12); \
title('(b)'); \
subplot(2,2,3); plot((0:tN-1),x); \
axis([0,tN,min(x),max(x)]); \
xlabel('Time (ms)','fontsize',12); \
ylabel('Amplitude', 'fontsize',12); \
title('(c)'); \
subplot(2,2,4); e=s-x; plot((0:tN-1),e); \
axis([0,tN,min(e),max(e)]); \
xlabel('Time (ms)','fontsize',12); \
ylabel('Amplitude', 'fontsize',12); \
title('(d)'); \
"; // send command to Matlab engine
engEvalString( ep, mCmd ); // delete mxArray
mxDestroyArray( mFs );
mxDestroyArray( ms );
mxDestroyArray( mx );
mxDestroyArray( mC );
system( "pause" );
engClose(ep); return 0;
}

 输出:

项目代码缺陷:

目前VS2015环境仅仅配置了SP++库环境和Matlab环境,SP++内部使用fftw并没有配置,因此后面如果需要再进行配置。

vs配置SP++3.0的更多相关文章

  1. win10下vs2015配置Opencv3.1.0过程详解

    下载安装Opencv3.1.0 下载Opencv3.1.0,进入官网,点击opencv for windows即可下载.  点击运行下载好的文件.实际上,opencv的安装程序就是解压缩文件,个人因为 ...

  2. 在Windows 2008/2008 R2 上配置IIS 7.0/7.5 故障转移集群

    本文主要是从:http://support.microsoft.com/kb/970759/zh-cn,直接转载,稍作修改裁剪而来,其中红色粗体部分,是我特别要说明的 若要配置 IIS 7.0 和 7 ...

  3. MyEclipse 8.5配置Tomcat 7.0

    MyEclipse 8.5配置Tomcat 7.0 在窗口(Windows)->首选项(Prefrences)->MyEclipse->Servers->Tomcat 6.x下 ...

  4. Ubuntu14.04 安装配置Hadoop2.6.0

    目前关于Hadoop的安装配置教程书上.官方教程.博客都有很多,但由于对Linux环境的不熟悉以及各种教程或多或少有这样那样的坑,很容易导致折腾许久都安装不成功(本人就是受害人之一).经过几天不断尝试 ...

  5. windows下配置lamp环境(0)---软件获取

    工作快一年了,还没有怎么配置过服务器环境,经常使用集成套件wampserver,为了复习配置wamp服务器 特意在虚拟机中测试安装步骤如下. 安装前步骤:下载软件.软件下载地址如下: 1.apache ...

  6. opencv-python:win7下,搭建python2.7.5环境,配置opencv3.1.0准备开工-OpenCV步步精深

    我的个人博客:点这里 搭建python2.7.5环境 下载python2.7.5 64位:https://www.python.org/ftp/python/2.7.5/python-2.7.5.am ...

  7. win10下vs2015配置Opencv3.1.0过程详解(转)

    下载安装Opencv3.1.0 下载Opencv3.1.0,进入官网,点击opencv for windows即可下载.  点击运行下载好的文件.实际上,opencv的安装程序就是解压缩文件,个人因为 ...

  8. vs2013配置opencv3.2.0

    工具/原料 l VS2013 l OpenCV3.20http://jaist.dl.sourceforge.net/project/opencvlibrary/opencv-win/3.2.0/op ...

  9. iis6下配置支持.net4.0&发布网站[转]

    iis6配置支持.net4.0 在win2003操作系统上发布两个网站,首先配置iis: 1.下载 .net framework 4.0   差不多48MB 2.安装 3.打开iis: 开始=> ...

随机推荐

  1. iOS开发学习-放大长图与屏幕等宽

    /* 需要得到一个图片的放大比例,这个比例就是屏幕的宽度与图片真实宽度的比值 */ CGFloat newZoomScale = LZ_SCREEN_WIDTH / [_photoImageView. ...

  2. 四则运算<C++>

    代码: #include<iostream> #define N 30 using namespace std; void main() { cout<<"***** ...

  3. Java基础第一节.Java简介

    第一节 Java简介 Java是一个由Sun公司开发而成的新一代的编程语言. Java语言是对软件开发有深远影响.应用前景广泛.具有丰富的类库.继承了C++的传统(摈弃了某些不足)广泛使用的网络编程语 ...

  4. 2018软工实践—Beta冲刺(3)

    队名 火箭少男100 组长博客 林燊大哥 作业博客 Beta 冲鸭鸭鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 软件接口编写修正 自动化测试脚本编写 技术文稿更新 展示GitHub当 ...

  5. Head First Java & static

  6. Java 单生产者消费者问题

    package com.cwcec.test; class Resource { private int count = 0; private boolean flag = false; public ...

  7. 1105 C程序的推导过程

  8. Python3.6 AES加密 pycrypto‎ 更新为 pycrypto‎demo | TypeError: Object type <class 'str'> cannot be passed to C code

    #!/usr/bin/env python# -*- coding:utf-8 -*-# @author: rui.xu# @update: jt.huang# 这里使用pycrypto‎demo库# ...

  9. redis哨兵机制一(转)

    概述 Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Master-slave的高可用方案时,假如 master宕机了,Redis本身(包括它的很多客户端) ...

  10. 网页正文提取,降噪的实现(readability/Document)

    安装: pip install readability-lxml 使用: # encoding:utf-8import html2textimport requestsimport refrom re ...