%
%      out=delay(in, Nsamp)
%
%      output signal is delayed by Nsamp relative to the input signal. 
%      input signal should have 1 channel only.
%
%      with a sample frequency of 50 kHz, each sample is 20 microseconds apart.
%      The first 20 ms of both signals are plotted.
%
function out=delay(in, Nsamp)

if size(in, 2)>1
   error('input should have only one channel!');
end

N=length(in);
out=zeros(N,1);

for i=1:N-Nsamp
   out(i+Nsamp)=in(i);
end

fs=50000;
p20=fs*20/1000;
dur=N/50; % duration in ms
if dur>20 pdur=p20;end
if dur<20 pdur=fs*dur/1000; end
   
figure(1);
clf
plot(in(1:pdur,1),'k-');   % plot up to the first 50 ms of the input signal
axis([0 p20 -1 1]);
set(gca, 'XTick',[0 p20/5 2*p20/5 3*p20/5 4*p20/5 p20]);
set(gca, 'XTickLabel',[' 0';' 4';' 8';'12';'16';'20']);
xlabel('Time [ms]', 'FontSize', 12);
ylabel('Amplitude [au]','FontSize',12);
hold on
plot(out(1:pdur,1),'r-');

