(*SOFT THRESHOLDING: ESEMPIO APPLICAZIONE NON LINEARITA' ISTANTANEA - GABRIEL HINE 30/11/2018*)

(*file audio*)
a=ExampleData[{"Audio","Apollo11SmallStep"},"Audio"]
AudioPlot[a,GridLines->{{},{-.5,-.2,-.1,0,.1,.2,.5}}]

(*hard thresholding*)
X = .1;
nl[x_]:= x (UnitStep[x-X] + UnitStep[-x-X] )
Plot[nl[x],{x,-1,1},Filling->Axis]
nla = nl[a]
AudioPlot[nla]

(*soft thresholding*)
nlsoft[x_]:= (x )*(1-Exp[(-x+X)/X]) UnitStep[x-X] +(x )*(1-Exp[(x+X)/X])UnitStep[-x-X] 
Plot[nlsoft[x],{x,-1,1},Filling->Axis]
nlsofta = nl[a]
AudioPlot[nlsofta]

(*filtraggio per rimuovere le frequenze spurie introdotte dalla non linearità*)
lp=LowpassFilter[nlsofta,Quantity[1600,"Hertz"],101]
AudioPlot[lp]