function y  = trunclaprnd(m, n, mu, sigma)
%LAPRND generate i.i.d. laplacian random number drawn from laplacian distribution
%   with mean mu and standard deviation sigma. 
%   mu      : mean
%   sigma   : standard deviation
%   [m, n]  : the dimension of y.
%   Default mu = 0, sigma = 1. 
%   For more information, refer to
%   http://en.wikipedia.org./wiki/Laplace_distribution

%   Author  : Elvis Chen (bee33@sjtu.edu.cn)
%   Date    : 01/19/07

%Check inputs
if nargin < 2
    error('At least two inputs are required');
end

if nargin == 2
    mu = 0; sigma = 1;
end

if nargin == 3
    sigma = 1;
end


% Generate Laplacian noise

u = rand(m, n);
b = sigma / sqrt(2);
c=1/(1-exp(-pi/b));
y = mu - b * sign(u/c+0.5*exp(-pi/b)-0.5).* log(1- 2* abs(u/c+0.5*exp(-pi/b)-0.5));
y=mod(y,2*pi);

