function output = blfdr_fixed(data, WaveletType, par, coarsest,  pi_0)
% Shrinkage by Local False Discovery Rate in the Wavelet domain,
% with prior probabilities fixed for all levels in the wavelet
% decomposition;
% Usage: output = blfdr_fixed(data, WaveletType, par, coarsest,  pi_0)
% Input: 
%           data - data vector - 1-d signal;
%           WaveletType - string, 'Haar', 'Beylkin', 'Coiflet', 'Daubechies',
%                                'Symmlet', 'Vaidyanathan','Battle'
%           par  -  integer, it is a parameter related to the support and vanishing
%                         moments of the wavelets.
%           coarsest - Coarsest Level of V_0;  L << J
%           pi_0  - prior probability of H_0 ( wavelet coef = 0)  set to be
%                     close to 1, pi_0  = 0.90 or 0.95 for example
%        
% Output:
%           output - 1-d denoised signal
%
%For reference please see "Local Bayesian False Discovery Rate Wavelet
%Shrinkage: Theory and Applications", 


N = length(data);  
num_lev = log2(N) - coarsest;
pi_1 = 1- pi_0;

%-----------------Wavelet decomposition
qmf = MakeONFilter(WaveletType, par);
wd = FWT_PO(data, coarsest, qmf);

   %---------------------------
    fin_ind=dyad(log2(N)-1);
    a=dyad(log2(N)-num_lev);
    sm_ind=1:a(1)-1; a=a(1);
    %--------mu&tau-----------!!!!!!!!!!!!!!!!---------
    finest_lev=wd(fin_ind);

    q1=prctile(finest_lev,25);
    q2=prctile(finest_lev,75);
    pseudos = abs(q2-q1)/1.5; 
    mu = 1/pseudos^2;      
    tau=(max((var(data)-1/mu)/(2*(1-pi_0)^2),10^(-6)))^0.5;

    %-------------------------------
    
    sigS=zeros(1,N);
    sigS(sm_ind) = wd(sm_ind);
    %------------------------------
    Bs=b_factor(wd(a:N),mu,tau);
    
    Ba = find(Bs < 1);
    sigS(a+Ba-1) = wd(a+Ba-1);
    
   output=IWT_PO(sigS, coarsest,qmf);
    