%% Poisson Statistics, Paul Klimov close all; clear all; clc % %% CUT CODE FOR OPTIMIZATION: % for j = 1:length(Counts) % for i = 1:max(Counts{j}) % Freq{j}(i)=length(find(Counts{j}==i)) % end % figure % %bar(1:1:length(Freq{j}),Freq{j}) % plot((1:1:length(Freq{j})),Freq{j},'o') % end %% Statistical Distributions k=0:1:30%k vector Bins=[10,3,5,11,5,11,17,11,5,8,9,12,16,24,6];% auto bins doesnt work well Dwell={'?','?','?','10ms','400ms','8ms',... '200ms','100ms','1s','400us','1ms','1ms','1ms','1ms','200ms'}; Pass={'?','?','?','120','1','300',... '20','20','1','1800','600','1200','2400','4800','3'}; for i = 1:15; Set{i}=xlsread(sprintf('Data%d.xls',i)); Counts{i}=Set{i}((6:end),2); Counts{i}=Counts{i}; Means{i}=(mean(Counts{i})); STD{i}=std(Counts{i}); VAR{i}=STD{i}.^2; DEV{i}=100*(Means{i}-VAR{i})/Means{i}; for j = 1:max(Counts{i}); Freq{i}(j)=length(find(Counts{i}==j)); end %poisson stats and normalization lambda{i}=Means{i}; Poiss{i}=lambda{i}.^k.*exp(-lambda{i})./factorial(k); H(i)=sum(Freq{i})/sum(Poiss{i}); %normalization % Gaussian stats and normalization Gauss{i}=1/(STD{i}*sqrt(2*pi))*exp(-(k-Means{i}).^2/(2*STD{i}.^2)); G(i)=sum(Freq{i})/sum(Gauss{i}); %plot if i<7; subplot(3,2,i); else if i ==7; figure end subplot(3,3,i-6); end hold on hist(Counts{i},Bins(i)); plot(k,G(i)*Gauss{i},'ro','linewidth',2); plot(k,H(i)*Poiss{i},'mo-'); hold off %plot options title(sprintf('Trial %d: Dwell %s, Passes %s \n Lambda=%d, Variance=%d',... i,Dwell{i},Pass{i},Means{i},VAR{i})); if i == 1 legend('Data','Normal','Poisson','location','best'); end if i ==7 legend('Data','Normal','Poisson','location','best'); end axis tight set(gcf,'color',[1,1,1]) end %% Various Plots Versus Deviations for i = 1:length(DEV); DEVMAT(i)=abs(DEV{i}); end DwellMAT=([0,0,0,10*10^-3,400*10^-3,8*10^-3,... 200*10^-3,100*10^-3,1,400*10^-6,1*10^-3,... 1*10^-3,1*10^-3,1*10^-3,200*10^-3]); Pass=[0,0,0,120,1,300,20,20,1,1800,600,1200,2400,4800,3]; PassTimesDwell=Pass.*DwellMAT; %Plots subplot(3,1,1) pdwell=polyfit(log(DwellMAT(4:end)),DEVMAT(4:end),1); smoothdwell=linspace(min(log(DwellMAT(4:end))),max(log(DwellMAT(4:end))),100); lsrdwell=polyval(pdwell,smoothdwell); plot(log(DwellMAT(4:end)),DEVMAT(4:end),'o',smoothdwell,lsrdwell); xlabel('log(Dwell)');ylabel('Deviation from Poisson'); subplot(3,1,2) ppass=polyfit(log(Pass(4:end)),DEVMAT(4:end),1); smoothpass=linspace(min(log(Pass(4:end))),max(log(Pass(4:end))),100); lsrpass=polyval(ppass,smoothpass); plot(log(Pass(4:end)),DEVMAT(4:end),'o',smoothpass,lsrpass); xlabel('log(Passes)');ylabel('Deviation from Poisson'); set(gcf,'color',[1,1,1]) subplot(3,1,3) ppassdwell=polyfit(log(PassTimesDwell(4:end)),DEVMAT(4:end),1); smoothpassdwell=linspace(min((PassTimesDwell(4:end))),max((PassTimesDwell(4:end))),100); lsrpassdwell=polyval(ppassdwell,smoothpassdwell); plot(PassTimesDwell(4:end),DEVMAT(4:end),'o',smoothpassdwell,lsrpassdwell); xlabel('Passes Multiplied by Dwell');ylabel('Deviation from Poisson'); figure stem3(log(DwellMAT(4:end)),log(Pass(4:end)),DEVMAT(4:end),'o'); xlabel('log(Dwell)');ylabel('log(Pass)');zlabel('Deviation'); set(gcf,'color',[1,1,1]);grid off; figure for i = 1:length(Means); MEANMAT(i)=(Means{i}); end plot(MEANMAT,DEVMAT,'o');xlabel('Lambda (Mean)');ylabel('deviation'); set(gcf,'color',[1,1,1]); %%