% 
% Aliasing Reduction in Clipped Signals
% Fabian Esqueda, Stefan Bilao and Vesa Välimäki
% Aalto University, Dept. of Signal Processing and Acoustics
% 
% MATLAB code used to implement Fig. 3
% 
% August 2015
% 
%%
clear all; 
close all; 
clc;

Fs = 44100;
Ts = 1/Fs;
range = 5;
t = -range:0.1:range;

% SETUP FIGURE
figure(1)
set(1, 'Color', 'w');
% set(1,'units','normalized','outerposition',[0 0 0.38 0.6])
fontsize = 16;
fontname = 'Times';
markersize = 16;
solidLineWidth = 2;

% TRIVIAL RAMP
for n=1:length(t)
   if t(n)<=0
    tr_ramp(n) = 0;
   else
    tr_ramp(n) = t(n);
   end
end
subplot(3,1,1), plot(t,tr_ramp,'k','LineWidth',2);
set(gca,'fontsize',fontsize,'fontname',fontname);
set(gca,'YTick',[0 2 4]);
set(gca,'YTicklabel',[{'0'},'2','4']');
set(gca,'XTick',[-4 -3 -2 -1 0 1 2 3 4]);
set(gca,'XTicklabel',[{'-4'},'-3','-2','-1','0','1','2','3','4']');
xlabel('(a)');
ylim([-0.5 5])
line(xlim, [0 0], 'color','k');  %x-axis



% BLAMP
BLEP = 0.5 + (1/pi)*sinint(pi*t);
BLAMP = t.*BLEP + (cos(pi*t)/(pi*pi));
subplot(3,1,2), plot(t,BLAMP,'k','LineWidth',solidLineWidth);
set(gca,'fontsize',fontsize,'fontname',fontname);
set(gca,'YTick',[0 2 4]);
set(gca,'YTicklabel',[{'0'},'2','4']');
set(gca,'XTick',[-4 -3 -2 -1 0 1 2 3 4]);
set(gca,'XTicklabel',[{'-4'},'-3','-2','-1','0','1','2','3','4']');
xlabel('(b)');
ylim([-0.5 5])
line(xlim, [0 0], 'color','k');  %x-axis


% RESIDUAL
residual = BLAMP - tr_ramp;
subplot(3,1,3), plot(t,residual,'k','LineWidth',solidLineWidth);
set(gca,'fontsize',fontsize,'fontname',fontname);
set(gca,'XTick',[-4 -3 -2 -1 0 1 2 3 4]);
set(gca,'XTicklabel',[{'-4'},'-3','-2','-1','0','1','2','3','4']');
xlabel({'Time (s)','(c)'}');
ylim([-0.05 0.12])
line(xlim, [0 0], 'color','k');  %x-axis


% print -deps2 Fig-trivial-bl-diff-ramp