当前位置:首页 > 代码 > 正文

小波变换c源代码(小波变换程序)

admin 发布:2022-12-19 04:39 89


今天给各位分享小波变换c源代码的知识,其中也会对小波变换程序进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

C语言怎么实现小波变换

#include stdio.h

#include stdlib.h

#define LENGTH 512//信号长度

/******************************************************************

* 一维卷积函数

*

* 说明: 循环卷积,卷积结果的长度与输入信号的长度相同

*

* 输入参数: data[],输入信号; core[],卷积核; cov[],卷积结果;

*  n,输入信号长度; m,卷积核长度.

*

* 李承宇, lichengyu2345@126.com

*

*  2010-08-18  

******************************************************************/

void Covlution(double data[], double core[], double cov[], int n, int m)

{

int i = 0;

int j = 0;

int k = 0;

//将cov[]清零

for(i = 0; i  n; i++)

{

cov[i] = 0;

}

//前m/2+1行

i = 0;

for(j = 0; j  m/2; j++, i++)

{

for(k = m/2-j; k  m; k++ )

{

cov[i] += data[k-(m/2-j)] * core[k];//k针对core[k]

}

for(k = n-m/2+j; k  n; k++ )

{

cov[i] += data[k] * core[k-(n-m/2+j)];//k针对data[k]

}

}

//中间的n-m行

for( i = m/2; i = (n-m)+m/2; i++)

{

for( j = 0; j  m; j++)

{

cov[i] += data[i-m/2+j] * core[j];

}

}

//最后m/2-1行

i = (n - m) + m/2 + 1;

for(j = 1; j  m/2; j++, i++)

{

for(k = 0; k  j; k++)

{

cov[i] += data[k] * core[m-j-k];//k针对data[k]

}

for(k = 0; k  m-j; k++)

{

cov[i] += core[k] * data[n-(m-j)+k];//k针对core[k]

}

}

}

/******************************************************************

* 一维小波变换函数

*

* 说明: 一维小波变换,只变换一次

*

* 输入参数: input[],输入信号; output[],小波变换结果,包括尺度系数和

* 小波系数两部分; temp[],存放中间结果;h[],Daubechies小波基低通滤波器系数;

* g[],Daubechies小波基高通滤波器系数;n,输入信号长度; m,Daubechies小波基紧支集长度.

*

* 李承宇, lichengyu2345@126.com

*

*  2010-08-19  

******************************************************************/

void DWT1D(double input[], double output[], double temp[], double h[], 

   double g[], int n, int m)

{

// double temp[LENGTH] = {0};//?????????????

int i = 0;

/*

//尺度系数和小波系数放在一起

Covlution(input, h, temp, n, m);

for(i = 0; i  n; i += 2)

{

output[i] = temp[i];

}

Covlution(input, g, temp, n, m);

for(i = 1; i  n; i += 2)

{

output[i] = temp[i];

}

*/

//尺度系数和小波系数分开

Covlution(input, h, temp, n, m);

for(i = 0; i  n; i += 2)

{

output[i/2] = temp[i];//尺度系数

}

Covlution(input, g, temp, n, m);

for(i = 1; i  n; i += 2)

{

output[n/2+i/2] = temp[i];//小波系数

}

}

void main()

{

double data[LENGTH];//输入信号

double temp[LENGTH];//中间结果

double data_output[LENGTH];//一维小波变换后的结果

int n = 0;//输入信号长度

int m = 6;//Daubechies正交小波基长度

int i = 0; 

char s[32];//从txt文件中读取一行数据

static double h[] = {.332670552950, .806891509311, .459877502118, -.135011020010, 

-.085441273882, .035226291882};

static double g[] = {.035226291882, .085441273882, -.135011020010, -.459877502118,

.806891509311, -.332670552950};

//读取输入信号

FILE *fp;

fp=fopen("data.txt","r");

if(fp==NULL) //如果读取失败

{

printf("错误!找不到要读取的文件/"data.txt/"/n");

exit(1);//中止程序

}

while( fgets(s, 32, fp) != NULL )//读取长度n要设置得长一点,要保证读到回车符,这样指针才会定位到下一行?回车符返回的是零值?是,非数字字符经过atoi变换都应该返回零值

{

// fscanf(fp,"%d", data[count]);//一定要有""啊!!!最后读了个回车符!适应能力不如atoi啊

data[n] = atof(s);

n++;

}

//一维小波变换

DWT1D(data, data_output, temp, h, g, n, m);

//一维小波变换后的结果写入txt文件

fp=fopen("data_output.txt","w");

//打印一维小波变换后的结果

for(i = 0; i  n; i++)

{

printf("%f/n", data_output[i]);

fprintf(fp,"%f/n", data_output[i]);

}

//关闭文件

fclose(fp);

}

有关C语言运行小波变换程序的时间问题。

我只听闻小波技术,从未试过哈,只做过傅里叶变换而已。。。但是,你可以分析下你输出的数据,正确与否,就用matlab的输出和C执行器的输出对比下,就知道靠不靠谱了啊。

如果嫌数据太多,可以找一些对比分析软件,如果实在无法全部分析,就弄几个特殊点,让程序就在那一些点输出对应值,对比matlab和C执行器的输出,多次换点,再对比,就知道靠不靠谱了。。。。你只是通过运算时间,怎么知道靠不靠谱呢,呵呵,要是你用多核DSP来算,只是一瞬间的事情,岂不是更不靠谱了。

要对图像进行小波变换去噪,可以用哪些图像处理库(C/C++)?

1.最简单的方法:

public static String reverse1(String str)

{

return new StringBuffer(str).reverse().toString();

}

2.最常用的方法:

public static String reverse3(String s)

{

char[] array = s.toCharArray();

String reverse = ""; //注意这是空串,不是null

for (int i = array.length - 1; i = 0; i--)

reverse += array[i];

return reverse;

}

3.常用方法的变形:

public static String reverse2(String s)

{

int length = s.length();

String reverse = ""; //注意这是空串,不是null

for (int i = 0; i length; i++)

reverse = s.charAt(i) + reverse;//在字符串前面连接, 而非常见的后面

return reverse;

}

4.C语言中常用的方法:

public static String reverse5(String orig)

{

char[] s = orig.toCharArray();

int n = s.length - 1;

int halfLength = n / 2;

for (int i = 0; i = halfLength; i++) {

char temp = s[i];

s[i] = s[n - i];

s[n - i] = temp;

}

return new String(s); //知道 char数组和String相互转化

}

求小波变换图像降噪的matlab代码

%源代码来自于在《MATLAB环境下基于小波变换的图像去噪》刘智clear;clc % 清理工作空间

load wbarb; % 装载原始图像

subplot(221); % 新建窗口

image(X); % 显示图像

colormap(map); % 设置色彩索引图

title('原始图像'); % 设置图像标题

axis square; % 设置显示比例,生成含噪图像并图示

init=2055615866; % 初始值

randn('seed',init); % 随机值

XX=X+8*randn(size(X)); % 添加随机噪声

subplot(222); % 新建窗口

image(XX); % 显示图像

colormap(map); % 设置色彩索引图

title('含噪图像'); % 设置图像标题

axis square; %用小波函数coif2 对图像XX 进行2 层分解

[c,l]=wavedec2(XX,2,'coif2'); % 分解

n=[1,2]; % 设置尺度向量

p=[10.28,24.08]; % 设置阈值向量,对高频小波系数进行阈值处理

%nc=wthcoef2('h',c,l,n,p,'s');

%nc=wthcoef2('v',c,l,n,p,'s');

nc=wthcoef2('d',c,l,n,p,'s');

X1=waverec2(nc,l,'coif2'); % 图像的二维小波重构

subplot(223); % 新建窗口

image(X1); % 显示图像

colormap(map); %设置色彩索引图

title('第一次消噪后的图像'); % 设置图像标题

axis square; % 设置显示比例,再次对高频小波系数进行阈值处理

%mc=wthcoef2('h',nc,l,n,p,'s');mc=wthcoef2('v',nc,l,n,p,'s');

mc=wthcoef2('d',nc,l,n,p,'s');

X2=waverec2(mc,l,'coif2'); % 图像的二维小波重构

subplot(224); % 新建窗口

image(X2); % 显示图像

colormap(map); % 设置色彩索引图

title('第二次消噪后的图像'); % 设置图像标题

axis square; % 设置显示比例

小波变换c源代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于小波变换程序、小波变换c源代码的信息别忘了在本站进行查找喔。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/2529.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载