%fan - f_analog: sampling of the "analog" signal
fan = 10;
% Time for signal -- 1000 samples, 100 seconds
t = 0:1/fan:100;
t = t(1:end-1);

% random signal repeating with period 200 samples
xin = [rand*ones(1,50), rand*ones(1,50), rand*ones(1,50), rand*ones(1,50)];
xin = [xin xin xin xin xin];

% Noise and delay
%% Very nice channel
tau = 1; % delay, in seconds;
peakNoise = 0.05;
%% Delayed channel
% tau = 12; % delay, in seconds;
% peakNoise = 0.05;
%% Noisy channel
% tau = 1; % delay, in seconds;
% peakNoise = 0.5;
%% Very poor channel
% tau = 12; % delay, in seconds;
% peakNoise = 0.5;
%% Perfect channel
% tau = 0;
% peakNoise = 0;

%% Simulate and plot
range = round([length(xin)-tau*fan+1:length(xin), 1:length(xin)-tau*fan]);
xout = xin(range) + peakNoise*2*(rand(size(xin))-0.5);
plot(t,xin,t,xout);

% % filter noise
% filtSize = 20;
% boxFilt = 1/filtSize*ones(1,filtSize);
% xfilt = filter(boxFilt,1,xout);
% plot(t,xin,t,xfilt);

shg