% Testing the wavelet transform
%
% Samuli Siltanen Oct 2016

% Convolution kernels for the Haar wavelet
h = [ 1 1]/sqrt(2);
g = [-1 1]/sqrt(2);

% Convolution kernels for the Daubechies 2 wavelet
%h = [1+sqrt(3) 3+sqrt(3) 3-sqrt(3) 1-sqrt(3)]/(4*sqrt(2));
%g = [h(4)      -h(3)     h(2)      -h(1)];

% Construct the signal
% SIGNAL OPTION 0:
f = zeros(1,128);
% SIGNAL OPTION 1: Synthetic signal with steps and noise
%f = zeros(1,1024);
%f(round(end/pi):3*end/4) = 1;
%f = f+0.05*randn(size(f));
% SIGNAL OPTION 2: acceleration signal recorded with a smartphone
%load lecture_acc.mat a1
%f(1:size(a1,1)) = a1(:,1);
% SIGNAL OPTION 3a: speech signal with audioread
% [f, FS] = audioread('Wtrans.m4a');
% f = f(1:2^17,1);
%save Wtrans f
% OPTION 3b: speech signal from .mat file (same signal than 3a)
%load Wtrans f

% Compute wavelet transform
J  = 7;
tr = Wavelet_tr(f,h,g,J);

% Apply filter
tr(1) = 1;
%tr((end/2+1):end) = 0;
%tr((256+1):end) = 0;
% tmp = sort(abs(tr));
% threshold = tmp(round(0.97*end));
% tr(abs(tr)<threshold) = 0;

% Inverse transform
f2 = Wavelet_tr_inv(tr,h,g,J);

% Show the result
figure(1)
clf
plot(f)
hold on
plot(f2,'r')
xlim([1 length(f)])
set(gca,'plotboxaspectratio',[3 1 1])

%print -dpng noisered_Haar.png

% sound(f,FS)
% pause(3)
% sound(f2,FS)

% Test the one-step transform and inverse
%[LP,HP] = Wavelet_tr_onestep(f,h,g)
%tr = [LP(:).',HP(:).'];
%f = Wavelet_tr_inv_onestep(tr,h,g)


