Question

Suppose that we have following array:

0.196238259763928
0.0886250228175519
0.417543614272817
0.182403230538167
0.136500793051860
0.389922187581014
0.0344012946153299
0.381603315802419
0.0997542838649466
0.274807632628596
0.601652859233616
0.209431489000677
0.396925294300794
0.0351587496999554
0.177321874549738
0.369200511917405
0.287108838007101
0.477076452316346
0.127558716868438
0.792431584110476
0.0459982776925879
0.612598437936600
0.228340227044324
0.190267907472804
0.564751537228850
0.00269368929400299
0.940538666131177
0.101588565140294
0.426175626669060
0.600215481734847
0.127859067121782
0.985881201195063
0.0945679498528667
0.950077461673118
0.415212985598547
0.467423473845033
1.24336273213410
0.0848695928658021
1.84522775800633
0.289288949281834
1.38792131632743
1.73186592736729
0.554254947026916
3.46075557122590
0.0872957577705428
4.93259798197976
2.03544238985229
3.71059303259615
8.47095716918618
0.422940369071662
25.2287636895831
4.14535369056670
63.7312173032838
152.080907190007
1422.19492782494
832.134744027851
0.0220089962114756
60.8238733887811
7.71053463387430
10.4151913932115
11.3141744831953
0.988978595613829
8.65598040591953
0.219820300144944
3.92785491164888
2.28370963778411
1.60232807621444
2.51086405960291
0.0181622519984990
2.27469230188760
0.487809730727909
0.961063613990814
1.90435488292485
0.515640996120482
1.25933693517960
0.0953200831348589
1.52851575480462
0.582109930768162
0.933543409438383
0.717947488528521
0.0445235241119612
1.21157308704582
0.0942421028083462
0.536069075206508
0.821400666720535
0.308956823975938
1.28706199713640
0.0339217632187507
1.19575886464231
0.0853733920496230
0.736744959694641
0.635218502184121
0.262305581223588
0.986899895695809
0.0398800891449550
0.758792061180657
0.134279188964854
0.442531129290843
0.542782326712391
0.377221037448628
0.704787750202814
0.224180325609783
0.998785634315287
0.408055416702400
0.329684702125840
0.522384453408780
0.154542718256493
0.602294251721841
0.240357912028348
0.359040779285709
0.525224294805813
0.427539247203335
0.624034405807298
0.298184846094056
0.498659616687732
0.0962076792277457
0.430092706132805
0.656212420735658
0.278310520474744
0.866037361133916
0.184971060800812
0.481149730712771
0.624405636807668
0.382388147099945
0.435350646037440
0.216499523971397
1.22960953802959
0.330841706900755
0.891793067878849
0.628241046456751
0.278687691121678
1.06358076764171
0.365652714373067
1.34921178081181
0.652888708375276
0.861138633227739
1.02878577330537
0.591174450919664
1.93594290806582
0.497631035062465
1.14486512201656
0.978067581547298
0.948931658572253
2.01004088022982
0.917415940349743
2.24124811810385
1.42691656876436
2.15636037453584
1.92812357585099
1.12786835077183
4.81721425534142
1.70055431306602
4.87939454466131
3.90293284926105
5.16542230018432
10.5783535493504
1.74023535081791
27.0572221453758
7.78813114379733
69.2528169436690
167.769806437531
1490.03057130613
869.247150795648
3.27543244752518
62.3527480644562
9.74192115073051
13.6074209231800
10.5686495478844
7.70239986387120
9.62850426896699
9.85304975304259
7.09026325332085
12.8782040428502
16.3163128995995
7.00070066635845
74.1532966917877
4.80506505312457
1042.52337489620
1510.37374385290
118.514435606795
80.7915675273571
2.96352221859211
27.7825124315786
1.55102367292252
8.66382951478539
5.02910503820560
1.25219344189599
7.72195587189507
0.356973215117373
6.06702456628919
1.01953617014621
2.76489896186652
3.35353608882459
0.793376336025486
4.90341095941571
0.00742857354167949
5.07665716731356
1.16863474789604
4.47635486149688
4.33050121578669
2.42974020115261
9.79494608790444
0.0568839453395247
22.9153086380666
4.48791386399205
59.6962194708933
97.8636220152072
1119.97978883924
806.144299041605
7.33252581243942
57.0699524267842
0.900104994068117
15.2791339483160
3.31266162202546
3.20809490583211
5.36617545130941
0.648122925703121
3.90480316969632
0.0338850542128927
2.58828964019220
0.543604662856673
1.16385064506181
1.01835324272839
0.172915006573539
1.55998411282069
0.00221570175453666
1.14803074836796
0.0769335878967426
0.421762398811163
0.468260146832541
0.203765185125597
0.467641715366303
0.00142988680149041
0.698088976126660
0.0413316717103625
0.190548157914037
0.504713663418641
0.325697764871308
0.375910057283262
0.123307135682793
0.331115262928959
0.00263961045860704
0.204555648718379
0.139008751575803
0.182936666944843
0.154943314848474
0.0840483576044629
0.293075999812128
0.00306911699543199
0.272993318570981
0.0864711337990886
0.280495615619829
0.0910123210559269
0.148399626645134
0.141945002415500
0.0512001531781583
0.0295283557338525

In MATLAB it is very easy to find peaks using findpeaks, like so:

[pxx_peaks,location] = findpeaks(Pxx);

If we plot pxx_peaks, we get

 plot(pxx_peaks)

enter image description here

Of course, besides these peaks, there are smaller peaks which are not shown on the picture, but my goal is to find all peaks which are 95-96% above all other peaks.

I have tried like this:

>> average = mean(pxx_peaks);
>> stand = std(pxx_peaks);
>> final_peaks = pxx_peaks( pxx_peaks > average + 3*stand ); 

The result of this is

>> final_peaks

final_peaks =

   1.0e+03 *

    1.4222
    1.4900
    1.5104
    1.1200

but how to return their corresponding locations? I want to write it as one m-file, so please help me

EDIT

also please help me in this question: can I parameterize the confidence interval? For instance instead of 95%, I want to find peaks that are 60% above then other peaks, is it possible?

Was it helpful?

Solution

Note that 3σ ≈ 99.73%

As for your first question, it's easy, you just have to keep track of the locations in the same way as you do for the peaks:

inds            = pxx_peaks > mean(pxx_peaks) + 3*std(pxx_peaks);
final_peaks     = pxx_peaks(inds); 
final_locations = location(inds);

plot(Pxx), hold on
plot(final_locations, final_peaks, 'r.')

As for your second question, that's a little more complicated. If you want to formulate it like you say, you'll have to convert a desired percentage to the correct number of σ. That involves an integration of the standard normal, and a root finding:

%// Convert confidence interval percentage to number-of-sigmas
F = @(P) fzero(@(sig) quadgk(@(x) exp(-x.^2/2),-sig,+sig)/sqrt(2*pi) - P/100, 1);

% // Repeat with the desired percentage
inds            = pxx_peaks > mean(pxx_peaks) + F(63)*std(pxx_peaks);  %// 63%
final_peaks     = pxx_peaks(inds); 
final_locations = location(inds);

plot(final_locations, final_peaks, 'r.')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top