The Discrete Wavelet Packet Transform (DWPT) is a method that decomposes both the approximation and detail parts of a signal, unlike the Discrete Wavelet Transform (DWT) which only decomposes the approximation part. The DWPT performs the transform step on both the low pass and high pass results. The coefficients at each level are obtained by recursively applying the DWT step to the approximation and detail results at the previous level. The process is illustrated in a diagram where "A" represents approximation, "D" represents detail, and the digit represents the level of decomposition.
------

SET SCHEMA DM_PAL;

DROP TABLE PAL_WPT_DATA_TBL;
CREATE COLUMN TABLE PAL_WPT_DATA_TBL (
	"ID" INTEGER,
	"VAL" DOUBLE
);

INSERT INTO PAL_WPT_DATA_TBL VALUES (1, 266.0);
INSERT INTO PAL_WPT_DATA_TBL VALUES (2, 145.9);
INSERT INTO PAL_WPT_DATA_TBL VALUES (3, 181.3);
INSERT INTO PAL_WPT_DATA_TBL VALUES (4, 119.3);
INSERT INTO PAL_WPT_DATA_TBL VALUES (5, 180.3);
INSERT INTO PAL_WPT_DATA_TBL VALUES (6, 168.5);
INSERT INTO PAL_WPT_DATA_TBL VALUES (7, 231.8);
INSERT INTO PAL_WPT_DATA_TBL VALUES (8, 224.5);
INSERT INTO PAL_WPT_DATA_TBL VALUES (9, 192.8);
INSERT INTO PAL_WPT_DATA_TBL VALUES (10, 122.9);
INSERT INTO PAL_WPT_DATA_TBL VALUES (11, 336.5);
INSERT INTO PAL_WPT_DATA_TBL VALUES (12, 185.9);
INSERT INTO PAL_WPT_DATA_TBL VALUES (13, 194.3);
INSERT INTO PAL_WPT_DATA_TBL VALUES (14, 149.5);

DROP TABLE PAL_PARAMETER_TBL;
CREATE COLUMN TABLE PAL_PARAMETER_TBL (
	"PARAM_NAME" VARCHAR(100),
	"INT_VALUE" INTEGER,
	"DOUBLE_VALUE" DOUBLE,
	"STRING_VALUE" VARCHAR(100)
);
INSERT INTO PAL_PARAMETER_TBL VALUES ('PADDING_TYPE', 1, NULL, NULL);
INSERT INTO PAL_PARAMETER_TBL VALUES ('LEVEL', 2, NULL, NULL);
INSERT INTO PAL_PARAMETER_TBL VALUES ('FILTER_TYPE', NULL, NULL, 'db2');
INSERT INTO PAL_PARAMETER_TBL VALUES ('OUT_TYPE', 1, NULL, NULL);

DROP TABLE PAL_COEFF_TBL;
CREATE COLUMN TABLE  PAL_COEFF_TBL(
	"NODE" INTEGER,
	"ID" INTEGER,
	"COEFF" DOUBLE
);

DROP TABLE PAL_STAT_TBL;
CREATE COLUMN TABLE  PAL_STAT_TBL(
	"NAME" NVARCHAR(100),
	"VAL" NVARCHAR(5000)
);

DO BEGIN
	lt_data = SELECT * FROM PAL_WPT_DATA_TBL;
	lt_ctrl = SELECT * FROM PAL_PARAMETER_TBL;
	CALL _SYS_AFL.PAL_WAVELET_PACKET_TRANSFORM(:lt_data, :lt_ctrl, lt_coeff, lt_stat);
	INSERT INTO PAL_COEFF_TBL SELECT * FROM :lt_coeff;
	INSERT INTO PAL_STAT_TBL SELECT * FROM :lt_stat;
END;
SELECT * FROM PAL_COEFF_TBL;
SELECT * FROM PAL_STAT_TBL;
