function [MSE, VAR, BIASSQ] = example2(signal_name, N, SNR, coarsest);
% Input:
% signal_name - name of the signal e.g. 'Doppler', 'Blocks', 'Bumps',
% 'HeaviSine' (defaul -' Doppler')
% 
% N - legnth of the signal (default 1024)
% SNR - Signal to Noise ratio (default 7)
% coarsest - coarsest level in wavelet decomposition (default floor(log2(
% log (N))) + 2)
%
%Output:
% MSE - vector of MSE for 3 different methods
% MSE(1) - MSE for BaFDR
% MSE(2) - MSE for BlFDR with fixed probabilities
% MSE(3) - MSE for BlFDR
% similarly for VAR and BIASSQ
%
% Example : [MSE, VAR, BIASSQ] = example2('Blocks', 1024, 7)
if nargin ==3; coarsest=floor(log2( log (N))) + 2; end;
if nargin ==2; SNR =7; coarsest=floor(log2( log (N))) + 2;end;
if nargin ==1; N = 1024; SNR = 7; coarsest=floor(log2( log (N))) + 2; end;
if nargin ==0; signal_name = 'Doppler'; N = 1024; SNR = 7; coarsest=floor(log2( log (N))) + 2; end;
    
if  strcmp(signal_name, 'Doppler')  
    qmf = 'Symmlet';
    par =8;
end;

if strcmp(signal_name, 'HeaviSine')
    qmf = 'Symmlet';
    par = 8;
end;

if strcmp(signal_name, 'Bumps')
    qmf = 'Daubechies';
    par =6;
end;

if strcmp(signal_name,'Blocks')
    qmf = 'Haar';
    par = 8;
end;
signal = MakeSignal(signal_name, N);
sigma = std(signal);
signal = signal.*SNR/sigma;
noise = randn(1,N);
data = signal + noise;

out1 = bafdr(data,qmf,par,coarsest,0.05,0.9);
out2 = blfdr_fixed(data,qmf , par, coarsest,  0.95);
out3 = blfdr(data, qmf, par, coarsest, 2.5);

MSE(1) = 1/N*sum((signal-out1).^2);
MSE(2) = 1/N*sum((signal-out2).^2);
MSE(3) = 1/N*sum((signal-out3).^2);

BIASSQ(1) = (mean(signal-out1))^2;
BIASSQ(2) = (mean(signal-out2))^2;
BIASSQ(3) = (mean(signal-out3))^2;

VAR(1) = MSE(1) - BIASSQ(1);
VAR(2) = MSE(2) - BIASSQ(2);
VAR(3) = MSE(3) - BIASSQ(3);





plot(data,'r');
hold on
plot(signal);
axis([0,N, min(data)-1, max(data)+1])
title('Signal + Noise');


figure(2);
plot(out1);
axis([0,N, min(data)-1, max(data)+1])
title('Restored Signal using BaFDR')

figure(3);
plot(out2);
axis([0,N, min(data)-1, max(data)+1])
title('Restored Signal using BlFDR with fixed probabilities')


figure(4)
plot(out3);
axis([0,N, min(data)-1, max(data)+1])
title('Restored Signal using BlFDR')
