Random Signals for Engineers using MATLAB and Mathcad Copyright 1999 Springer Verlag NY Example 7.6 Experimental Receiver Operating Curve In the example we will conduct a detection experiment and by observing the data from a series of experiments we will construct and plot the ROC. We will compare the results to the theoretical ROC. We begin by generating two distributions that correspond to Hypothesis 0 and 1. Since we desire the distributions to be gaussian we can either use the Matlab built in function for generation of gaussian distributed random variables or use the techniques developed in Section 4. We will use the techniques developed in Section 4. Select a set of random variable that are uniformly distributed in order to generate 2 gaussian random variables N=800; u=rand(1,N); v=rand(1,N); uu=rand(1,N); vv=rand(1,N); The two normal random variable sets are generated using the vector array format that allows the indicated operation to be executed on every element of the input vector. The gaussian variables R with 0 are generated with a mean = 0 corresponding to hypothesis 0 and similarly, D, with a mean = 1 for hypothesis 1. Both signal are with a variance = 1. R=0+1*cos(2*pi*v).*sqrt(-2*log(u)); D=1+1*cos(2*pi*vv).*sqrt(-2*log(uu)); The random variables R correspond to hypothesis 0 and D 1. Now sort the vector sets of random variable according to their numerical values to facilitate counting of the experimental data they represent. r=sort(R ); d= sort(D); The experimental procedure is rather simple. We select a random variable from either set and compare it to the threshold. If it's values are above the threshold we declare a detection. If indeed the value came from the hypothesis 1 set, we score a detection. If the value came from hypothesis 0 we score a false alarm. We systematically use all the random values in both sets or R and D. In order to facilitate the counting we may construct the experiments in using the valueless in R and D in any order. Specifically , we may use the values in sorted order. The threshold values that we range over can be selected as the values of the D distribution. In order to evaluate the number of detections we can now just count the value of random variables below the threshold or the index value. This is facilitated by sorting the D vector to d. The number of PD is N minus the values to the index since we are computing the number of misses rather detections. We create the counting functions for PD as n(i)=i/N. Since the values of d are used as the thresholds we must create a counting function to evaluate the PFA by counting all the values of r that are above d. Here we use the sorted values because we desire only the number of experiments that give a FA and do not care in which order the results came out. The counting function computes the number of values of r that exceed d by evaluating to 1 when this is true and the summer ranges over all the r values for j=1:N k=find(d(j)<r); x(j)=length(k)/N; y(j)=1-j/N; end For comparison we compute the analytical ROC from Example 7.6 as for comparison lam=0.001:0.1:30; PD10=1-cnorm(log(lam)-1.0/2,0,1); PF10=1-cnorm(log(lam)+1.0/2,0,1); plot(x,y); hold on; plot(PF10,PD10); hold off xlabel 'PF - Prob. False Alarm' ylabel 'Pd - Prob. Detection' 1 0.9 0.8 Pd - Prob. Detection 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 PF - Prob. False Alarm 0.8 0.9 1 The data for the ROC is plotted and the comparison of the experimental and analytical values compares favorably. In order to verify that the random variables generated have the correct mean and standard deviation to correspond to hypothesis 0 and 1 we can experimentally verify that the data is correct mean(d), std(d) mean(r ), std(r ) ans = 0.9954 ans = 1.0017 ans = 0.0574 ans = 0.9809 We can also plot the data on a linear scale to show the relative values from the two distributions. subplot(2,1,1) plot(d,ones(1,N),'r+',mean(d),1,'bdiamond') axis([-4 4 .7 1.3]) ylabel 'Dectect' xlabel 'values' subplot(2,1,2) plot(r,ones(1,N),'rx',mean(r),1,'bsquare') axis([-4 4 .7 1.3]) xlabel 'values' ylabel 'False Alarm' Dectect 1.2 1.1 1 0.9 0.8 0.7 -4 -3 -2 -1 0 values 1 2 3 4 -3 -2 -1 0 values 1 2 3 4 False Alarm 1.2 1.1 1 0.9 0.8 0.7 -4