%
%
%
%define time
Fs = 10000;
dt = 1/Fs;
t = 0:dt:1;

%define APs
AP1amp = 1;
AP1dur1 = .001;
AP1dur2 = .002;
AP1prob = .003;
AP2amp = AP1amp*.5;

%make single AP
%by concantenating two 1/2 sin cycles
oneT = 0:dt:(AP1dur1+AP1dur2);
oneAP = AP1amp*sin(2*pi/(2*AP1dur1)*oneT).*(oneT<=AP1dur1) + ...
    AP1amp*0.5*sin(2*pi/(2*AP1dur2)*(oneT+AP1dur1)).*(oneT>AP1dur1) ;

%make a bunch of APs
locationAP1 = rand(size(t))<AP1prob; %poisson
%locationAP1 = mod([1:length(t)],457)==0; %uniform
vAP = conv(locationAP1,oneAP);
vAP = vAP(1:length(t)); %truncate
locationAP2 = rand(size(t))<AP1prob; %poisson
vAP2 = conv(locationAP2,oneAP*AP2amp);
vAP = vAP + vAP2(1:length(t)); %truncate

%make gaussian noise plus 60 Hz interference
noiseAmp = 1;
interAmp = 1;
vnoise = noiseAmp*randn(size(t)) + interAmp*sin(60*2*pi*t);

%now add niose to APs and 
vnoise = vAP ;


nplot=2
clf

subplot(nplot,1,1)
plot(oneAP)
title('One AP')
legend('input AP')

subplot(nplot,1,2)
plot(t,vAP)
title('typical poisson APs')
set(gca,'ylim',[-1 1.5])



%