Test on k-th order statistics vs Max test

%% P(k) vs Max test

clear all

sigma = 1;

n=100;

MC=30000;

for k=1:10;

M0=sigma*randn(n,MC);

 

A=.3;

 

if k==1

for j=1:MC

M1(:,j)=(A*cos(2*pi*(1:n)*1/n+rand*2*pi))’;

end

else

 

for j=1:MC

y=A*cos(2*pi*(1:n)*1/n+rand*2*pi);

for i=2:k;

y=y+(A*cos(2*pi*(1:n)*i/n+rand*2*pi));

end

M1(:,j)=y’;

end

end

 

M1=M1+M0;

 

 

P0 = 1/n*(abs(fft(M0))).^2;

P1 = 1/n*(abs(fft(M1))).^2;

 

 

P0=P0(2:n/2-1,:);

P1 = P1(2:n/2-1,:);

 

% max test

max0 = max(P0);

max1 = max(P1);

 

gamma=linspace(min(max0),max(max1),10000);

 

for i=1:length(gamma)

pfa0(i)=sum((max0>=gamma(i)));

pdet0(i)=sum((max1>=gamma(i)));

end

pfa0=pfa0/MC;

pdet0=pdet0/MC;

 

 

 

% P(k) test

for i=1:MC

a0=P0(:,i);Pk0(:,i)=sort(a0,’descend’);

a1=P1(:,i);Pk1(:,i)=sort(a1,’descend’);

end

 

t0 = (Pk0(k,:));

t1 = (Pk1(k,:));

 

gamma=linspace(min(t0),max(t1),10000);

 

 

 

for i=1:length(gamma)

pfak0(i)=sum((t0>=gamma(i)));

pdetk0(i)=sum((t1>=gamma(i)));

end

 

pfak0=pfak0/MC;

pdetk0=pdetk0/MC;

 

 

figure

set(gcf,’Color’,’w’)

plot(pfa0,pdet0)

hold on

plot(pfak0,pdetk0,’r’)

legend(‘max’,’P(k)’,2)

axis square

grid

title([‘k = ‘, num2str(k), ‘ A = ‘, num2str(A) ])

end