Max vs Fisher test and Pfa of Fisher test

% Test Fisher

clear all

close all

 

sigma = .5;

n=100;

MC=300000;

for k=1:1;

 

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;

 

% Fisher

m=length(P0(:,1));

D0=sum(P0);

D1=sum(P1);

% stat Fisher

T0 = max0./D0;

T1 = max1./D1;

 

gamma=linspace(min(T0),max(T1),10000);

 

pfafth = zeros(1,10000);

 

for i=1:length(gamma)

pfaf0(i)=sum((T0>=gamma(i)));

pdetf0(i)=sum((T1>=gamma(i)));

 

for j=1:m

pfafth(i)= pfafth(i)+(-1)^(j-1)*nchoosek(m,j)*(max(1-j*gamma(i), 0))^(m-1);

 

end

end

pfaf0=pfaf0/MC;

pdetf0=pdetf0/MC;

 

 

 

figure

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

plot(pfa0,pdet0)

hold on

plot(pfaf0,pdetf0,’r’)

legend(‘max’,’Fisher’,2)

axis square

grid

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

 

figure

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

semilogy(gamma,pfaf0)

hold on

semilogy(gamma,pfafth,’r’)

legend(‘max’,’Fisher’,1)

axis tight

end