%%% EE 148 - Some figures for lecture 2 %%% (c) March 29 2000 - P. Perona Caltech %% Modified April 3, 2003 SIZE = 128; %% Width and height of image SIZE2 = SIZE/2; RADIUS = 3; POS_JITTER = 10; NOISE_LEVEL = [ 0 0.1 0.3 1 ]; noise = randn(SIZE,SIZE); ima = zeros(SIZE,SIZE); XX = round(POS_JITTER*randn(1))+[SIZE2-RADIUS:SIZE2+RADIUS]; %% X coordinates of signal YY = round(POS_JITTER*randn(1))+[SIZE2-RADIUS:SIZE2+RADIUS]; %% Y coordinates of signal ima(YY,XX) = 1; %% Show image with different noise levels for i=1:length(NOISE_LEVEL), figure(i); clf; imagesc(ima+NOISE_LEVEL(i)*noise); colormap gray; axis off end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% ROC NOISE_LEVEL = [0.1 0.3 1 2]; %% St. dev. of noise N_EXPER = 1000; figure(10); clf for i=1:length(NOISE_LEVEL), R_S = 1 + NOISE_LEVEL(i)*randn(1,N_EXPER); %% Response to signal R_N = NOISE_LEVEL(i)*randn(1,N_EXPER); %% Response to noise [NS,XS] = hist(R_S); [NN,XN] = hist(R_N); figure(10); subplot(2,4,1+(i-1)*2); plot(XS,NS/N_EXPER,'g',XN,NN/N_EXPER,'r','LineWidth',2); xlabel('strength of response'); ylabel('relative frequency'); title(['Response to signal (green) and no-signal (red) for \sigma=' num2str(NOISE_LEVEL(i))]); %% Calculate and display ROC R_all = sort([R_S R_N]); for j=1:length(R_all), FA(j)=100*sum(R_N>=R_all(j))/N_EXPER; %% Percent false alarms PD(j)=100*sum(R_S>=R_all(j))/N_EXPER; %% Percent detected end; figure(10); subplot(2,4,2+(i-1)*2); plot(FA,PD,'LineWidth',2); xlabel('percent false alarms'); ylabel('percent detected'); title(['ROC curve for noise \sigma=' num2str(NOISE_LEVEL(i))]); end;