/******************************************************************
* 一维小波变换函数
* 说明:一维小波变换,只变换一次
* 输入参数:input[],输入信号;output[],小波变换结果,包括尺度系数和
* 小波系数两部分;temp[],存放中间结果;h[],Daubechies小波基低通滤波器系数;
* g[],Daubechies小波基高通滤波器系数;n,输入信号长度;m,Daubechies小波基紧支集长度。
******************************************************************/
voidDWT1D_1(doubleinput[],doubleoutput0[],doubleoutput1[],doubletemp[],doubleh[],
doubleg[],intn,intm)
{
//doubletemp[LENGTH]={0};//?????????????
inti=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+m-1;i+=2)
{
output0[i/2]=temp[i];//尺度系数,进行了2抽值,即尺度空间,低频概貌部分
}
Covlution(input,g,temp,n,m);
for(i=1;i《n+m-1;i+=2)
{
//output[i]=temp[i];
output1[(i-1)/2]=temp[i];//小波系数,已经进行了2抽取,即高频细节部分
}
}
voidDWT1D_2(doubleinput[],doubleAA2[],doubleDA2[],doubleAD2[],doubleDD2[],doubletemp0[],doubletemp1[],doubletemp[],doubleh[],
doubleg[],intn,intm)
{
DWT1D_1(input,temp0,temp1,temp,h,g,n,m);
inta1=(m+n)/2;
DWT1D_1(temp0,AA2,DA2,temp,h,g,a1,m);
intd1=(n+m-4)/2;
DWT1D_1(temp1,AD2,DD2,temp,h,g,d1,m);
}
voidDWT1D_3(doubleinput[],doubleAAA3[],doubleDAA3[],doubleADA3[],doubleDDA3[],doubleAAD3[],doubleDAD3[],doubleADD3[],doubleDDD3[],
doubletemp0[],doubletemp1[],doubletemp2[],doubletemp3[],doubletemp00[],doubletemp11[],doubletemp[],doubleh[],doubleg[],intn,intm)
{
DWT1D_2(input,temp0,temp1,temp2,temp3,temp00,temp11,temp,h,g,n,m);
intaa2=(m+n)/4;
DWT1D_1(temp0,AAA3,DAA3,temp,h,g,aa2,m);
intda2=(n+3*m-8)/4;
DWT1D_1(temp1,ADA3,DDA3,temp,h,g,da2,m);
intad2=(n+3*m-4)/4;
DWT1D_1(temp2,AAD3,DAD3,temp,h,g,ad2,m);
intdd2=(n+3*m-12)/4;
DWT1D_1(temp3,ADD3,DDD3,temp,h,g,dd2,m);
}
voidmain()
{
doubledata[LENGTH];//输入信号
doubletemp0[(LENGTH+DB_LENGTH)/4];//先定义了一个中间结果
doubletemp1[(LENGTH+DB_LENGTH*3-8)/4];
doubletemp2[(LENGTH+DB_LENGTH*3-4)/4];
doubletemp3[(LENGTH+DB_LENGTH*3-12)/4];
doubletemp00[(LENGTH+DB_LENGTH)/2];
doubletemp11[(LENGTH+DB_LENGTH-4)/2];
doubletemp[LENGTH+DB_LENGTH-1];
doubleAAA3[(LENGTH+DB_LENGTH*5)/8];//一维小波变换后的结果
doubleDAA3[(LENGTH+DB_LENGTH*5-16)/8];
doubleADA3[(LENGTH+DB_LENGTH*7-8)/8];
doubleDDA3[(LENGTH+DB_LENGTH*7-24)/8];
doubleAAD3[(LENGTH+DB_LENGTH*7-4)/8];
doubleDAD3[(LENGTH+DB_LENGTH*7-20)/8];
doubleADD3[(LENGTH+DB_LENGTH*7-12)/8];
doubleDDD3[(LENGTH+DB_LENGTH*7-28)/8];
intaaa3=(LENGTH+DB_LENGTH*5)/8;//一维小波变换后的结果数组的长度
intdaa3=(LENGTH+DB_LENGTH*5-16)/8;
intada3=(LENGTH+DB_LENGTH*7-8)/8;
intdda3=(LENGTH+DB_LENGTH*7-24)/8;
intaad3=(LENGTH+DB_LENGTH*7-4)/8;
intdad3=(LENGTH+DB_LENGTH*7-20)/8;
intadd3=(LENGTH+DB_LENGTH*7-12)/8;
intddd3=(LENGTH+DB_LENGTH*7-28)/8;
intn=0;//输入信号长度
intm=8;//Daubechies正交小波基长度
inti=0;
chars[32];//从txt文件中读取一行数据
/*//DB3
staticdoubleh[]={.332670552950,.806891509311,.459877502118,-.135011020010,
-.085441273882,.035226291882};
staticdoubleg[]={.035226291882,.085441273882,-.135011020010,-.459877502118,
.806891509311,-.332670552950};
*/
//DB4
staticdoubleh[]={0.2303778133088964,0.7148465705529154,0.6308807679398587,-0.0279837694168599,-0.1870348117190931,0.0308413818355607,0.0328830116668852,-0.0105974017850690};//h[],Daubechies小波基低通滤波器系数;
staticdoubleg[]={-0.0105974017850690,-0.0328830116668852,0.0308413818355607,0.1870348117190931,-0.0279837694168599,-0.6308807679398587,0.7148465705529154,-0.2303778133088964};//g[],Daubechies小波基高通滤波器系数
评论
查看更多