www.gusucode.com > phased 案例源码 matlab代码程序 > phased/ThresholdForRealValuedSignalInWGNExample.m

    %% Threshold for Real-Valued Signal in White Gaussian Noise
% This example shows how to empirically verify the probability of false alarm
% for a real-valued signal in white Gaussian noise.

% Copyright 2015 The MathWorks, Inc.


%%
% Determine the required signal-to-noise (SNR) in decibels for the NP
% detector when the maximum tolerable false-alarm probability is $10^{-3}$.
Pfa = 1e-3;
T = npwgnthresh(Pfa,1,'real');

%%
% Determine the actual threshold corresponding to the desired false-alarm
% probability, assuming the variance is 1.
variance = 1;
threshold = sqrt(variance*db2pow(T));

%%
% Verify empirically that the threshold results in the desired false-alarm
% probability under the null hypothesis. To do so, simulate 1 million
% samples of a Gaussian random variable, and determine the proportion of
% samples that exceed the threshold.
rng default
N = 1e6;
x = sqrt(variance)*randn(N,1);
falsealarmrate = sum(x>threshold)/N

%%
% The measured false-alarm rate agrees with the simulation value.
%%
% Plot the first 10,000 samples and then plot a red horizontal line to
% indicate the threshold.
x1 = x(1:1e4);
plot(x1)
line([1 length(x1)],[threshold threshold],'Color','red')
xlabel('Sample')
ylabel('Value')
%%
% You can see that only a few sample values exceed the threshold. This result is
% expected because of the low false-alarm probability.