|
回复 楼主 shanghai 的帖子
虽然帖子过期了 我还是回一下吧 这个程序是我前几天做的!在函数调用上有一点点问题。
自己改一下就能用了!!我的输入数据是从文件输入的!
#include "math.h"
#include "stdio.h"
#include "conio.h"
FILE *outF;
int DB4DWT(int Data[],int n) /* Haar小波的分解算法 */
{
int i,j;
int half=n>>1;
int tmp[4];
double h0=0.5,h1=0.5;
double g0=-0.5,g1=0.5;
if(!(outF=fopen("result.txt","wt")))
{
printf("\n Cant open the out file\n");
exit(0);
}
printf("\nthe filter of wavelet\n");
fprintf(outF,"the filter of wavelet\n");
if(n>=4)
{
for(j=0;j<half;j++)
{
tmp[j]=Data[(2*j)%n]*h1+Data[(2*j+1)%n]*h0;
tmp[j+half]=Data[(2*j)%n]*g1+Data[(2*j+1)%n]*g0;
}
for(i=0;i<n;i++)
{
Data=tmp;
}
}
}
void IDWT(int Data[],int n) /* Haar小波的重构算法 */
{
int t,shuju[4],a[2]={1,2},a1[2]={3,-1},b[4]={0,0,0,0},b1[4]={0,0,0,0},c[4],d[4];
double h0=1,h1=1;
double g0=1,g1=-1;
int i,j;
for(i=0;i<4;i+=2)
{
b[i+1]=a[i/2];
b1[i+1]=a1[i/2] ;
}
printf("++++++++++up sampling+++++++++++\n");
fprintf(outF,"++++++++++up sampling+++++++++++\n");
for(i=0;i<4;i++)
{
printf("%d %d\n",b,b1);
fprintf(outF,"%d %d\n",b,b1);
}
n=4;
for(j=0;j<4;j++)
{
c[j]=b[(j)%n]*h1+b[(j+1)%n]*h0;
d[j]=b1[(j)%n]*g1+b1[(j+1)%n]*g0;
Data[j]=c[j]+d[j];
}
printf("++++++++++recombination+++++++++\n");
fprintf(outF,"++++++++++recombination+++++++++\n");
for(j=0;j<4;j++)
printf("%d\n",Data[j]);
for(i=0;i<4;i++)
fprintf(outF,"%d\n",Data);
}
void main()
{ FILE *dat;
int a[4];
int i,n=4; int half=n>>1;
if((dat=fopen("c:\\33.txt","rt"))==NULL){
printf("open file error");
getch();
exit(1);}
for(i=0;i<4;i++){
fscanf(dat,"%d",&a);
}
fclose(dat);
printf("data:");for(i=0;i<4;i++){
printf(" %d ",a);
}
getchar();
DB4DWT(a,n);
printf("+++++++approximate part++++++++\n");
fprintf(outF,"++++++++++approximate part+++++++++\n");
for(i=0;i<half;i++)
{
printf("%d\n",a);
fprintf(outF,"%d\n",a);
}
printf("+++++++++detail part+++++++++++\n");
fprintf(outF,"++++++++++detail part+++++++++\n");
for(i=half;i<n;i++)
{
printf("%d\n",a);
fprintf(outF,"%d\n",a);
}
IDWT(a,n);
fclose(outF);
getch();
} |
|