www.gusucode.com > signal 案例源码程序 matlab代码 > signal/ProbabilityOfDetectionAndExponentialExample.m
%% False-Alarm Probabilities % Generate 100 samples of a sinusoidal signal at a sample rate of 1 Hz. % Specify an amplitude of 0.75 and a frequency of % $0.6/2\pi\approx0.096\;\rm Hz$. Embed the signal in white noise of % variance 0.902. Reset the random number generator for repeatable results. % Copyright 2015 The MathWorks, Inc. rng default X0 = 0.75; f0 = 0.6; vr = 0.902; Nsamp = 100; t = 1:Nsamp; X = X0*cos(f0*(1:Nsamp))+randn(1,Nsamp)*sqrt(vr); %% % Discard 10% of the samples at random. Plot the signal. X(randperm(Nsamp,Nsamp/10)) = NaN; plot(t,X,'o') %% % Compute and plot the normalized power spectrum. Annotate the levels that % correspond to false-alarm probabilities of 50%, 10%, 1%, and 0.01%. If % you generate many 90-sample white noise signals with variance 0.902, then % half of them have one or more peaks higher than the 50% line, 10% have % one or more peaks higher than the 10% line, and so on. Pfa = [50 10 1 0.01]/100; Pd = 1-Pfa; [pxx,f,pth] = plomb(X,1:Nsamp,'normalized','Pd',Pd); plot(f,pxx,f,pth*ones(size(f'))) xlabel('f') text(0.3*[1 1 1 1],pth-.5,[repmat('P_{fa} = ',[4 1]) num2str(Pfa')]) %% % In this case, the peak is high enough that only about 0.01% of the % possible signals can attain it. % % Use |plomb| with no output arguments to repeat the calculation. The plot % is now logarithmic, and the levels are drawn in terms of detection % probabilities. plomb(X,1:Nsamp,'normalized','Pd',Pd)