function generate_poisson_trains mean_IPI=100 %in ms -- mean time from the beginning of one stimulus pulse to the beginning of the next min_IPI=20 %in ms -- min time " " num_trains=1 num_pulses=500 %each stim pulse,including the last one, is followed by an IPI pulse_duration=1 %in ms sampling_duration=50000; %in milliseconds sampling_rate=10000; %in kHz samples_per_ms=(sampling_rate/1000); samples_per_trigger=((sampling_duration/1000)*sampling_rate); head_blank=500*samples_per_ms; %used to insert empty space at the beginning of each trial %scaling each train to equal the duration of a tetanic train w/ the same # %of pulses at the same mean frequency (the last pulse, like all others, is %followed by an IPI) scaled_length=(num_pulses-1)*(samples_per_ms*(mean_IPI-pulse_duration)) z=repmat(ceil(.5*min_IPI*samples_per_ms),(num_pulses-1),num_trains) while min(min(z))<(min_IPI*samples_per_ms) %this will repeat the process until a matrix with no values below the min is found z=poiss_intervals_tablemaker(mean_IPI,samples_per_ms,num_pulses,num_trains,scaled_length); end z gee=min(z) gigi=min(min(z)) global poisson_train1 global poisson_train2 global poisson_train3 global poisson_train4 global poisson_train5 global poisson_train6 global poisson_train7 global poisson_train8 global poisson_train9 global poisson_train10 global poisson_train11 global poisson_train12 global poisson_train13 global poisson_train14 global poisson_train15 z=round(z); m=1; n=1; holder=[]; for m=1:num_trains holder_col=repmat(0,head_blank,1); holder_col(300*samples_per_ms:(310*samples_per_ms)-1)=-.05; for n=1:(num_pulses-1) holder_col=cat(1,holder_col,ones(pulse_duration*samples_per_ms,1)); holder_col=cat(1,holder_col,zeros(z(n,m),1)); n=n+1; end holder_col=cat(1,holder_col,ones(pulse_duration*samples_per_ms,1)); %adding on the last pulse holder_col=cat(1,holder_col,zeros((samples_per_trigger-length(holder_col)),1)); holder=cat(2,holder,holder_col); m=m+1; end p=1; for p=1:num_trains if p==1 %this part is not flexible; the max number of trains is preset here poisson_train1=holder(:,p); end figure(p) plot(holder(:,p)) p=p+1; end % %making the tetanic train and plotting it % global tetanic_train % tetanic_train=repmat(0,(num_pulses*mean_IPI),1); % r=1; % for r=1:num_pulses % tetanic_train(((r-1)*mean_IPI)+1)=1; %similarly must take care of zero possibility in poisson trains % r=r+1; % end % figure(num_trains+1) % plot(tetanic_train)