📄 filterbank.c
字号:
/*****************************************************************************/
/* Author: Brendt Wohlberg (Los Alamos National Laboratory). */
/* Copyright 2001 University of California. */
/*****************************************************************************/
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include "FilterBank.h"
int fltbankirr_std(FltBankIrr* fltbankirr, FilterBankName fbn) {
static const int haar_L[] = {1, 1};
static const int haar_off[] = {0, 0};
static const float haar_alpha0[] = {-1.0};
static const float haar_alpha1[] = { 0.5};
static const float* haar_alpha[] = {haar_alpha0, haar_alpha1};
static const int fb2_6_L[] = {1, 1, 3};
static const int fb2_6_off[] = {0, 0, -1};
static const float fb2_6_alpha2[] = {-0.25, 0.0, 0.25};
static const float* fb2_6_alpha[] = {haar_alpha0, haar_alpha1, fb2_6_alpha2};
static const int fb2_10_L[] = {1, 1, 5};
static const int fb2_10_off[] = {0, 0, -2};
static const float fb2_10_alpha2[] = {0.046875,-0.343750,0.000000,0.343750,-0.046875};
static const float* fb2_10_alpha[] = {haar_alpha0, haar_alpha1,
fb2_10_alpha2};
static const int fb3_5_L[] = {2, 2};
static const int fb3_5_off[] = {0,-1};
static const float fb3_5_alpha0[] = { 0.50, 0.50};
static const float fb3_5_alpha1[] = {-0.25, -0.25};
static const float* fb3_5_alpha[] = {fb3_5_alpha0, fb3_5_alpha1};
static const int fb5_3_off[] = {-1,0};
static const float fb5_3_alpha0[] = {-0.50, -0.50};
static const float fb5_3_alpha1[] = { 0.25, 0.25};
static const float* fb5_3_alpha[] = {fb5_3_alpha0, fb5_3_alpha1};
static const float fb6_2_alpha0[] = { 1.00};
static const float fb6_2_alpha1[] = {-0.50};
static const float* fb6_2_alpha[] = {fb6_2_alpha0, fb6_2_alpha1,
fb2_6_alpha2};
static const int daub9_7_L[] = {2, 2, 2, 2};
static const int daub9_7_off[] = {-1,0,-1,0};
static const float daub9_7_alpha0[] = {-1.586134342, -1.586134342};
static const float daub9_7_alpha1[] = {-0.05298011857,-0.05298011857};
static const float daub9_7_alpha2[] = {0.8829110755, 0.8829110755};
static const float daub9_7_alpha3[] = {0.4435068520, 0.4435068520};
static const float* daub9_7_alpha[] = {daub9_7_alpha0, daub9_7_alpha1,
daub9_7_alpha2, daub9_7_alpha3};
static const float* fb10_2_alpha[] = {fb6_2_alpha0, fb6_2_alpha1,
fb2_10_alpha2};
switch(fbn) {
case Haar:
fltbankirr_initialise(fltbankirr, 2, 2, 1,
haar_L, haar_off, haar_alpha, 1.0);
break;
case FB2_6:
fltbankirr_initialise(fltbankirr, 2, 3, 1,
fb2_6_L, fb2_6_off, fb2_6_alpha, 1.0);
break;
case FB2_10:
fltbankirr_initialise(fltbankirr, 2, 3, 1,
fb2_10_L, fb2_10_off, fb2_10_alpha, 1.0);
break;
case FB3_5:
fltbankirr_initialise(fltbankirr, 1, 2, 0,
fb3_5_L, fb3_5_off, fb3_5_alpha, 1.0);
break;
case FB5_3:
fltbankirr_initialise(fltbankirr, 1, 2, 1,
fb3_5_L, fb5_3_off, fb5_3_alpha, 1.0);
break;
case FB6_2:
fltbankirr_initialise(fltbankirr, 2, 3, 0,
fb2_6_L, fb2_6_off, fb6_2_alpha, 1.0);
break;
case Daub9_7:
fltbankirr_initialise(fltbankirr, 1, 4, 1,
daub9_7_L, daub9_7_off, daub9_7_alpha, 1.0);
break;
case FB10_2:
fltbankirr_initialise(fltbankirr, 2, 3, 0,
fb2_10_L, fb2_10_off, fb10_2_alpha, 1.0);
break;
default:
return 0;
}
return 1;
}
void fltbankirr_initialise(FltBankIrr* fltbankirr, int Filt_Cat, int N_LS,
int m0, const int* L, const int* off,
const float** alpha, float K) {
int s,k;
fltbankirr->Filt_Cat = Filt_Cat;
fltbankirr->N_LS = N_LS;
fltbankirr->m0 = m0;
fltbankirr->L = malloc(sizeof(int)*N_LS);
assert(fltbankirr->L);
for (s = 0; s < N_LS; s++)
fltbankirr->L[s] = L[s];
fltbankirr->off = malloc(sizeof(int)*N_LS);
assert(fltbankirr->off);
for (s = 0; s < N_LS; s++)
fltbankirr->off[s] = off[s];
fltbankirr->alpha = malloc(sizeof(float*)*N_LS);
assert(fltbankirr->alpha);
for (s = 0; s < N_LS; s++) {
fltbankirr->alpha[s] = malloc(sizeof(float)*L[s]);
assert(fltbankirr->alpha[s]);
for (k = 0; k < L[s]; k++)
fltbankirr->alpha[s][k] = alpha[s][k];
}
fltbankirr->K = K;
}
void fltbankirr_destroy(FltBankIrr* fltbankirr) {
int s;
for (s = 0; s < fltbankirr->N_LS; s++)
free(fltbankirr->alpha[s]);
free(fltbankirr->alpha);
free(fltbankirr->off);
free(fltbankirr->L);
}
void fltbankirr_print(FltBankIrr* fltbankirr) {
int s, k;
int* off = fltbankirr->off;
int* L = fltbankirr->L;
float** alpha = fltbankirr->alpha;
printf("First step updates %s phase\n", fltbankirr->m0?"odd":"even");
for (s = 0; s < fltbankirr->N_LS; s++) {
printf("Step %2d:\n", s);
for (k = off[s]; k < off[s] + L[s]; k++)
printf("%+14d ", k);
printf("\n");
for (k = 0; k < L[s]; k++)
printf("%+14e ", alpha[s][k]);
printf("\n");
}
}
int fltbankrev_std(FltBankRev* fltbankrev, FilterBankName fbn) {
static const int haar_L[] = {1, 1};
static const int haar_off[] = {0, 0};
static const int haar_alpha0[] = {-1};
static const int haar_alpha1[] = { 1};
static const int* haar_alpha[] = {haar_alpha0, haar_alpha1};
static const int haar_epsilon[] = {0, 1};
static const int haar_beta[] = {0, 1};
static const int fb2_6_L[] = {1, 1, 3};
static const int fb2_6_off[] = {0, 0, -1};
static const int fb2_6_alpha2[] = {-1, 0, 1};
static const int* fb2_6_alpha[] = {haar_alpha0, haar_alpha1, fb2_6_alpha2};
static const int fb2_6_epsilon[] = {0, 1, 2};
static const int fb2_6_beta[] = {0, 1, 2};
static const int fb2_10_L[] = {1, 1, 5};
static const int fb2_10_off[] = {0, 0, -2};
static const int fb2_10_alpha2[] = {3, -22, 0, 22, -3};
static const int* fb2_10_alpha[] = {haar_alpha0, haar_alpha1, fb2_10_alpha2};
static const int fb2_10_epsilon[] = {0, 1, 6};
static const int fb2_10_beta[] = {0, 1, 32};
static const int fb3_5_L[] = {2, 2};
static const int fb3_5_off[] = {0,-1};
static const int fb3_5_alpha0[] = { 1, 1};
static const int fb3_5_alpha1[] = {-1, -1};
static const int* fb3_5_alpha[] = {fb3_5_alpha0, fb3_5_alpha1};
static const int fb3_5_epsilon[] = {1, 2};
static const int fb3_5_beta[] = {1, 2};
static const int fb5_3_off[] = {-1,0};
static const int fb5_3_alpha0[] = {-1, -1};
static const int fb5_3_alpha1[] = { 1, 1};
static const int* fb5_3_alpha[] = {fb5_3_alpha0, fb5_3_alpha1};
static const int fb6_2_alpha0[] = { 1};
static const int fb6_2_alpha1[] = {-1};
static const int* fb6_2_alpha[] = {fb6_2_alpha0, fb6_2_alpha1, fb2_6_alpha2};
static const int fb6_2_beta[] = {0, 0, 0};
static const int* fb10_2_alpha[] = {fb6_2_alpha0, fb6_2_alpha1,
fb2_10_alpha2};
static const int fb10_2_beta[] = {0, 0, 0};
switch(fbn) {
case Haar:
fltbankrev_initialise(fltbankrev, 2, 2, 1, haar_L, haar_off, haar_alpha,
haar_beta, haar_epsilon);
break;
case FB2_6:
fltbankrev_initialise(fltbankrev, 2, 3, 1, fb2_6_L, fb2_6_off,
fb2_6_alpha, fb2_6_beta, fb2_6_epsilon);
break;
case FB2_10:
fltbankrev_initialise(fltbankrev, 2, 3, 1, fb2_10_L, fb2_10_off,
fb2_10_alpha, fb2_10_beta, fb2_10_epsilon);
break;
case FB3_5:
fltbankrev_initialise(fltbankrev, 1, 2, 0, fb3_5_L, fb3_5_off,
fb3_5_alpha, fb3_5_beta, fb3_5_epsilon);
break;
case FB5_3:
fltbankrev_initialise(fltbankrev, 1, 2, 1, fb3_5_L, fb5_3_off,
fb5_3_alpha, fb3_5_beta, fb3_5_epsilon);
break;
case FB6_2:
fltbankrev_initialise(fltbankrev, 2, 3, 0, fb2_6_L, fb2_6_off,
fb6_2_alpha, fb6_2_beta, fb2_6_epsilon);
break;
case FB10_2:
fltbankrev_initialise(fltbankrev, 2, 3, 0, fb2_10_L, fb2_10_off,
fb10_2_alpha, fb10_2_beta, fb2_10_epsilon);
break;
default:
return 0;
}
return 1;
}
void fltbankrev_initialise(FltBankRev* fltbankrev, int Filt_Cat, int N_LS,
int m0, const int* L, const int* off,
const int** alpha, const int* beta,
const int* epsilon) {
int s,k;
fltbankrev->Filt_Cat = Filt_Cat;
fltbankrev->N_LS = N_LS;
fltbankrev->m0 = m0;
fltbankrev->L = malloc(sizeof(int)*N_LS);
assert(fltbankrev->L);
for (s = 0; s < N_LS; s++)
fltbankrev->L[s] = L[s];
fltbankrev->off = malloc(sizeof(int)*N_LS);
assert(fltbankrev->off);
for (s = 0; s < N_LS; s++)
fltbankrev->off[s] = off[s];
fltbankrev->alpha = malloc(sizeof(int*)*N_LS);
assert(fltbankrev->alpha);
for (s = 0; s < N_LS; s++) {
fltbankrev->alpha[s] = malloc(sizeof(int)*L[s]);
assert(fltbankrev->alpha[s]);
for (k = 0; k < L[s]; k++)
fltbankrev->alpha[s][k] = alpha[s][k];
}
fltbankrev->beta = malloc(sizeof(int*)*N_LS);
assert(fltbankrev->beta);
for (s = 0; s < N_LS; s++)
fltbankrev->beta[s] = beta[s];
fltbankrev->epsilon = malloc(sizeof(int*)*N_LS);
assert(fltbankrev->epsilon);
for (s = 0; s < N_LS; s++)
fltbankrev->epsilon[s] = epsilon[s];
}
void fltbankrev_destroy(FltBankRev* fltbankrev) {
int s;
for (s = 0; s < fltbankrev->N_LS; s++)
free(fltbankrev->alpha[s]);
free(fltbankrev->alpha);
free(fltbankrev->off);
free(fltbankrev->L);
free(fltbankrev->beta);
free(fltbankrev->epsilon);
}
void fltbankrev_print(FltBankRev* fltbankrev) {
int s, k;
int* L = fltbankrev->L;
int* off = fltbankrev->off;
int** alpha = fltbankrev->alpha;
int* epsilon = fltbankrev->epsilon;
printf("First step updates %s phase\n", fltbankrev->m0?"odd":"even");
for (s = 0; s < fltbankrev->N_LS; s++) {
printf("Step %2d (*2^%d):\n", s, epsilon[s]);
for (k = off[s]; k < off[s] + L[s]; k++)
printf("%+14d ", k);
printf("\n");
for (k = 0; k < L[s]; k++)
printf("%+14d ", alpha[s][k]);
printf("\n");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -