function [ y ] = dist_with_booster( wave,gain,mix,cf_Hz,bw_Hz,boost,fs)
%function [ y ] = dist_with_booster( wave,gain,mix,cf_Hz,bw_Hz,boost,fs)
    % Distortion based on the function provided in Dafx book with
    % band-boost filter added to it in order to boost the weaker
    % frequencies or mask those we dont want.
    %  Usage: function [ y ] = dist_with_booster(
    %  wave,gain,mix,cf_Hz,bw_Hz,boost,fs)
    %  wave     input signal
    %  gain     amount of distortion, >0
    %  mix      mix of original and distorted sound, 1=only distorted
    %  cf_Hz    passband central freq. (in Hz, cycles/sec)
    %  boost    gain at fm for boost/cut (=1 original signal
    %                                 >1 boost
    %                                 <1 cut
    %                                 =0 notch filter)
    %  bw_Hz    width of bandpass transformation at -3dB (in Hz, cycles/sec)
    %  fs       the frequency of signal sampling (in Hz, cycles/sec) 

[w] = my_regalia_mitra(wave, cf_Hz, boost, bw_Hz, fs)
q = w * gain/max(abs(w));%Attributing the gain
z = sign(-q).*(1-exp(sign(-q).*q));%function implementation
y = mix * z* max(abs(w))/max(abs(z))+(1-mix)*w;%mix with the original sound
y=y*max(abs(w))/max(abs(y));%normalization 


function [Y] = my_regalia_mitra(X, cf_Hz, k, bw_Hz, Fs)
% function [Y] = my_regalia_mitra(X, cf_Hz, k, bw_Hz, Fs)
%REGALIA_MITRA   Allpass filtering based on the Regalia-Mitra model.
%                This function can be used several times to build a
%                parallel EQ filtering system in a cascade.
%                (IEEE Trans. ASSP-35, no.1, January, 1987)
%
% Usage : [Y] = regalia_mitra(X, w0, k, bw)
%  X    input signal X[n]
%  cf_Hz   passband central freq. (in Hz, cycles/sec)
%  k    gain at fm for boost/cut (=1 original signal
%                                 >1 boost
%                                 <1 cut
%                                 =0 notch filter)
%  bw_Hz   width of bandpass transformation at -3dB (in Hz, cycles/sec)
%  fs   the frequency of signal sampling (in Hz, cycles/sec)
%  Y    output signal Y[n] after the regalia-mitra filtering operation on X[n]
%
%
% Author: Davide Renzi, d.renzi@infocom.uniroma1.it
%         INFOCOM Dept. University of Rome "La Sapienza"

% driving parameters

w0 = 2 * pi * cf_Hz/Fs; %  w0 is the passband central freq. (in rads/sample)
bw = 2 * pi * bw_Hz/Fs; %  w0 is the passband central freq. (in rads/sample)

k0 = k/2;
k1 = (1-tan(bw/2))/(1+tan(bw/2));
k2 = -cos(w0);

% extract base function A(z)
b = [k1 k2*(1+k1) 1]; % num
a = [1 k2*(1+k1) k1]; % den

% operate the filtering
Y = filter(b,a,X);

Y = (0.5*X)+(0.5*Y) + (k0*X)-(k0*Y);