%Illustrates the chi-squared PDF for different degrees of freedom. %Not the PDF is normalized in each case to have a mean value of one. clear; figure(2); clf; hold on; col='krybmcgkrybmcgkry'; df=.001; for ct=2:2:20; vals=df/2:df:5*ct; pdf=chi2pdf(vals,ct); cdf=chi2cdf(vals,ct); pl=find(cdf<=0.025); ci(1)=vals(pl(end))/ct; fill([vals(pl)/ct fliplr(vals(pl)/ct) vals(1)],[zeros(1,length(pl)) fliplr(ct*pdf(pl)) ct*pdf(1)],col(ct/2)); pl=find(cdf>=0.975); ci(2)=vals(pl(1))/ct; fill([vals(pl)/ct fliplr(vals(pl)/ct) vals(pl(1))/ct],[zeros(1,length(pl)) fliplr(ct*pdf(pl)) ct*pdf(pl(1))],col(ct/2)); h=plot(vals/ct,ct*pdf,col(ct/2)); set(h,'linewidth',2); h=ylabel('probability'); font(h,16); h=xlabel('power density'); font(h,16); font(gca,16); if ct==2; axis([0 5 0 1.5]); else; axis([0 5 0 1.5]); end; title(['modified \chi^2 probability density function with ',num2str(ct),' degrees of freedom']); [ci; chi2confPH(0.95,ct)], pause; end;