1

I have a set of a Gaussian randomly generated data. The way i obtain this data is of no importance, but its trough a particle code with diffusion.

I know that there are functions in python that can do this, however i cannot afford to write this data in a file at each time step, and then analyse it after because i need it for a diagnostic. Therefore i need to calculate it in the code.

My code is written in Fortran 95.

An example of the data i need to find the full width at half maximum is this (full data is down bellow) enter image description here

However as you can see, it is a bit to noisy.

By hand i calculated this length to be 0.00235 (Because this is the starting data i know this length to be 0.0023548200450309495, so it is really close). However i had to estimate a maximum (33.6) with my cursor and then find the length with my cursor.

Is there a way to do it with code in Fortran? It can also be the algorithm to use if you don't know Fortran (i can translate it to Fortran by my self)

Do not hesitate to ask any question.

Edit: I forgot to mention that i already do the calculation of Sigma trough:

Sigma = Sum( (x - Av(x))**2 )/N

the thing is that this gives me an answer, but because of some physical properties, at least at the start of a simulation it does not give me the right value, it works for latter time steps but not at the start.

   1.89624932667106                0
   1.89626438944774                0
   1.89627945222442                0
   1.89629451500110                0
   1.89630957777777                0
   1.89632464055445                0
   1.89633970333113                0
   1.89635476610781                0
   1.89636982888449                0
   1.89638489166117                0
   1.89639995443785                0
   1.89641501721453                0
   1.89643007999121                0
   1.89644514276789                0
   1.89646020554457                0
   1.89647526832125                0
   1.89649033109793                0
   1.89650539387460                0
   1.89652045665128                0
   1.89653551942796                0
   1.89655058220464                0
   1.89656564498132                0
   1.89658070775800                0
   1.89659577053468                0
   1.89661083331136                0
   1.89662589608804                1
   1.89664095886472                1
   1.89665602164140                0
   1.89667108441808                0
   1.89668614719475                0
   1.89670120997143                0
   1.89671627274811                0
   1.89673133552479                1
   1.89674639830147                0
   1.89676146107815                0
   1.89677652385483                0
   1.89679158663151                1
   1.89680664940819                0
   1.89682171218487                1
   1.89683677496155                0
   1.89685183773823                0
   1.89686690051490                0
   1.89688196329158                0
   1.89689702606826                0
   1.89691208884494                0
   1.89692715162162                1
   1.89694221439830                3
   1.89695727717498                1
   1.89697233995166                0
   1.89698740272834                0
   1.89700246550502                0
   1.89701752828170                1
   1.89703259105838                1
   1.89704765383505                0
   1.89706271661173                1
   1.89707777938841                3
   1.89709284216509                0
   1.89710790494177                1
   1.89712296771845                1
   1.89713803049513                1
   1.89715309327181                1
   1.89716815604849                1
   1.89718321882517                3
   1.89719828160185                1
   1.89721334437853                2
   1.89722840715520                2
   1.89724346993188                0
   1.89725853270856                2
   1.89727359548524                1
   1.89728865826192                1
   1.89730372103860                1
   1.89731878381528                1
   1.89733384659196                1
   1.89734890936864                2
   1.89736397214532                2
   1.89737903492200                3
   1.89739409769868                2
   1.89740916047535                2
   1.89742422325203                2
   1.89743928602871                1
   1.89745434880539                4
   1.89746941158207                2
   1.89748447435875                2
   1.89749953713543                3
   1.89751459991211                9
   1.89752966268879                3
   1.89754472546547                1
   1.89755978824215                2
   1.89757485101883                3
   1.89758991379551                4
   1.89760497657218                3
   1.89762003934886                2
   1.89763510212554                5
   1.89765016490222                4
   1.89766522767890                4
   1.89768029045558                4
   1.89769535323226                3
   1.89771041600894                6
   1.89772547878562                9
   1.89774054156230                3
   1.89775560433898                5
   1.89777066711566                4
   1.89778572989233                5
   1.89780079266901                5
   1.89781585544569                9
   1.89783091822237                5
   1.89784598099905                4
   1.89786104377573                7
   1.89787610655241                9
   1.89789116932909                3
   1.89790623210577                4
   1.89792129488245                8
   1.89793635765913                9
   1.89795142043581                6
   1.89796648321248                9
   1.89798154598916                5
   1.89799660876584                8
   1.89801167154252               11
   1.89802673431920                7
   1.89804179709588                7
   1.89805685987256                6
   1.89807192264924                9
   1.89808698542592               15
   1.89810204820260                9
   1.89811711097928                9
   1.89813217375596                7
   1.89814723653263                8
   1.89816229930931               15
   1.89817736208599                9
   1.89819242486267                6
   1.89820748763935               14
   1.89822255041603               10
   1.89823761319271               13
   1.89825267596939                8
   1.89826773874607               16
   1.89828280152275               13
   1.89829786429943               15
   1.89831292707611                8
   1.89832798985278               19
   1.89834305262946               16
   1.89835811540614               21
   1.89837317818282               19
   1.89838824095950               11
   1.89840330373618               11
   1.89841836651286               20
   1.89843342928954               25
   1.89844849206622               17
   1.89846355484290               19
   1.89847861761958               25
   1.89849368039626               13
   1.89850874317293               17
   1.89852380594961               21
   1.89853886872629               14
   1.89855393150297               24
   1.89856899427965               14
   1.89858405705633               21
   1.89859911983301               22
   1.89861418260969               17
   1.89862924538637               18
   1.89864430816305               27
   1.89865937093973               22
   1.89867443371641               20
   1.89868949649308               30
   1.89870455926976               27
   1.89871962204644               30
   1.89873468482312               31
   1.89874974759980               23
   1.89876481037648               24
   1.89877987315316               41
   1.89879493592984               21
   1.89880999870652               32
   1.89882506148320               31
   1.89884012425988               46
   1.89885518703656               20
   1.89887024981324               28
   1.89888531258991               35
   1.89890037536659               32
   1.89891543814327               32
   1.89893050091995               24
   1.89894556369663               36
   1.89896062647331               47
   1.89897568924999               31
   1.89899075202667               38
   1.89900581480335               32
   1.89902087758003               34
   1.89903594035671               47
   1.89905100313339               29
   1.89906606591006               36
   1.89908112868674               43
   1.89909619146342               32
   1.89911125424010               41
   1.89912631701678               39
   1.89914137979346               45
   1.89915644257014               37
   1.89917150534682               46
   1.89918656812350               46
   1.89920163090018               31
   1.89921669367686               54
   1.89923175645354               33
   1.89924681923021               43
   1.89926188200689               39
   1.89927694478357               50
   1.89929200756025               46
   1.89930707033693               45
   1.89932213311361               54
   1.89933719589029               65
   1.89935225866697               42
   1.89936732144365               59
   1.89938238422033               46
   1.89939744699701               48
   1.89941250977369               56
   1.89942757255036               50
   1.89944263532704               36
   1.89945769810372               55
   1.89947276088040               57
   1.89948782365708               38
   1.89950288643376               48
   1.89951794921044               69
   1.89953301198712               56
   1.89954807476380               62
   1.89956313754048               52
   1.89957820031716               58
   1.89959326309384               55
   1.89960832587051               49
   1.89962338864719               60
   1.89963845142387               49
   1.89965351420055               59
   1.89966857697723               56
   1.89968363975391               47
   1.89969870253059               48
   1.89971376530727               67
   1.89972882808395               62
   1.89974389086063               61
   1.89975895363731               62
   1.89977401641399               52
   1.89978907919066               42
   1.89980414196734               68
   1.89981920474402               49
   1.89983426752070               63
   1.89984933029738               53
   1.89986439307406               64
   1.89987945585074               66
   1.89989451862742               60
   1.89990958140410               57
   1.89992464418078               79
   1.89993970695746               54
   1.89995476973414               55
   1.89996983251081               64
   1.89998489528749               70
   1.89999995806417               65
   1.90001502084085               60
   1.90003008361753               61
   1.90004514639421               67
   1.90006020917089               63
   1.90007527194757               65
   1.90009033472425               41
   1.90010539750093               59
   1.90012046027761               73
   1.90013552305429               51
   1.90015058583097               55
   1.90016564860764               56
   1.90018071138432               51
   1.90019577416100               57
   1.90021083693768               50
   1.90022589971436               60
   1.90024096249104               81
   1.90025602526772               52
   1.90027108804440               62
   1.90028615082108               45
   1.90030121359776               63
   1.90031627637444               46
   1.90033133915112               64
   1.90034640192779               58
   1.90036146470447               61
   1.90037652748115               60
   1.90039159025783               58
   1.90040665303451               58
   1.90042171581119               59
   1.90043677858787               44
   1.90045184136455               62
   1.90046690414123               47
   1.90048196691791               52
   1.90049702969459               49
   1.90051209247127               45
   1.90052715524794               48
   1.90054221802462               54
   1.90055728080130               65
   1.90057234357798               57
   1.90058740635466               51
   1.90060246913134               57
   1.90061753190802               42
   1.90063259468470               47
   1.90064765746138               54
   1.90066272023806               48
   1.90067778301474               46
   1.90069284579142               45
   1.90070790856809               53
   1.90072297134477               55
   1.90073803412145               49
   1.90075309689813               57
   1.90076815967481               50
   1.90078322245149               37
   1.90079828522817               35
   1.90081334800485               52
   1.90082841078153               55
   1.90084347355821               43
   1.90085853633489               36
   1.90087359911157               45
   1.90088866188824               48
   1.90090372466492               37
   1.90091878744160               52
   1.90093385021828               47
   1.90094891299496               39
   1.90096397577164               35
   1.90097903854832               42
   1.90099410132500               35
   1.90100916410168               25
   1.90102422687836               23
   1.90103928965504               36
   1.90105435243172               23
   1.90106941520839               34
   1.90108447798507               32
   1.90109954076175               23
   1.90111460353843               40
   1.90112966631511               37
   1.90114472909179               29
   1.90115979186847               25
   1.90117485464515               30
   1.90118991742183               35
   1.90120498019851               27
   1.90122004297519               36
   1.90123510575187               27
   1.90125016852855               23
   1.90126523130522               30
   1.90128029408190               26
   1.90129535685858               19
   1.90131041963526               35
   1.90132548241194               30
   1.90134054518862               23
   1.90135560796530               30
   1.90137067074198               24
   1.90138573351866               26
   1.90140079629534               22
   1.90141585907202               24
   1.90143092184870               17
   1.90144598462537               21
   1.90146104740205               20
   1.90147611017873               16
   1.90149117295541               19
   1.90150623573209               17
   1.90152129850877               14
   1.90153636128545               15
   1.90155142406213               17
   1.90156648683881               22
   1.90158154961549               11
   1.90159661239217                8
   1.90161167516885               19
   1.90162673794552               18
   1.90164180072220               15
   1.90165686349888               17
   1.90167192627556               17
   1.90168698905224               17
   1.90170205182892               16
   1.90171711460560               11
   1.90173217738228               12
   1.90174724015896               15
   1.90176230293564               16
   1.90177736571232               12
   1.90179242848900               16
   1.90180749126567               10
   1.90182255404235               10
   1.90183761681903               11
   1.90185267959571               13
   1.90186774237239               16
   1.90188280514907               13
   1.90189786792575               14
   1.90191293070243               12
   1.90192799347911                8
   1.90194305625579               14
   1.90195811903247                6
   1.90197318180915               10
   1.90198824458582                5
   1.90200330736250                9
   1.90201837013918               12
   1.90203343291586                5
   1.90204849569254                5
   1.90206355846922                9
   1.90207862124590                8
   1.90209368402258                4
   1.90210874679926                3
   1.90212380957594                6
   1.90213887235262                7
   1.90215393512930                6
   1.90216899790597                5
   1.90218406068265               10
   1.90219912345933                5
   1.90221418623601                4
   1.90222924901269                8
   1.90224431178937                6
   1.90225937456605                9
   1.90227443734273                8
   1.90228950011941                2
   1.90230456289609                4
   1.90231962567277                3
   1.90233468844945                3
   1.90234975122612                5
   1.90236481400280                3
   1.90237987677948                4
   1.90239493955616                5
   1.90241000233284                3
   1.90242506510952                2
   1.90244012788620                1
   1.90245519066288                3
   1.90247025343956                2
   1.90248531621624                1
   1.90250037899292                2
   1.90251544176960                4
   1.90253050454628                1
   1.90254556732295                1
   1.90256063009963                3
   1.90257569287631                0
   1.90259075565299                0
   1.90260581842967                3
   1.90262088120635                0
   1.90263594398303                1
   1.90265100675971                1
   1.90266606953639                1
   1.90268113231307                1
   1.90269619508975                5
   1.90271125786643                2
   1.90272632064310                1
   1.90274138341978                0
   1.90275644619646                3
   1.90277150897314                0
   1.90278657174982                2
   1.90280163452650                1
   1.90281669730318                0
   1.90283176007986                0
   1.90284682285654                0
   1.90286188563322                1
   1.90287694840990                1
   1.90289201118658                0
   1.90290707396325                0
   1.90292213673993                3
   1.90293719951661                1
   1.90295226229329                1
   1.90296732506997                1
   1.90298238784665                0
   1.90299745062333                2
   1.90301251340001                0
   1.90302757617669                1
   1.90304263895337                0
   1.90305770173005                0
   1.90307276450673                0
   1.90308782728340                1
   1.90310289006008                1
   1.90311795283676                0
   1.90313301561344                0
   1.90314807839012                0
   1.90316314116680                0
   1.90317820394348                0
   1.90319326672016                0
   1.90320832949684                0
   1.90322339227352                0
   1.90323845505020                0
   1.90325351782688                1
   1.90326858060355                0
   1.90328364338023                0
   1.90329870615691                0
   1.90331376893359                0
   1.90332883171027                2
   1.90334389448695                0
   1.90335895726363                0
   1.90337402004031                0
   1.90338908281699                0
   1.90340414559367                0
   1.90341920837035                1
   1.90343427114703                0
   1.90344933392370                0
   1.90346439670038                0
   1.90347945947706                0
   1.90349452225374                0
   1.90350958503042                0
   1.90352464780710                0
   1.90353971058378                0
   1.90355477336046                0
   1.90356983613714                0
   1.90358489891382                0
   1.90359996169050                0
   1.90361502446718                1
   1.90363008724385                0
   1.90364515002053                0
   1.90366021279721                0
   1.90367527557389                0
   1.90369033835057                0
   1.90370540112725                0
   1.90372046390393                0
   1.90373552668061                0
   1.90375058945729                0
   1.90376565223397                0

Gundro
  • 139
  • 9
  • Does this answer your question? [Finding the full width half maximum of a peak](https://stackoverflow.com/questions/10582795/finding-the-full-width-half-maximum-of-a-peak) – veryreverie Mar 18 '21 at 16:26
  • It looks promising. I had completely forgot to use interpolation, maybe it will work, i will try it. – Gundro Mar 19 '21 at 07:57
  • @Gundro Interpolation is bad for noisy data, you want curve fitting, like in the last answer there. – Vladimir F Героям слава Mar 19 '21 at 08:20
  • What exactly do you mean by "it works for latter time steps but not at the start."? Does your system display transient behavior or do you mean that the error is too large for just a small number of sample sizes? – jack Mar 19 '21 at 10:23

1 Answers1

3

Assuming a Gaussian distribution you can compute the FWHM using the mean value and standard deviation.

An example implementation

program main
  implicit none
  integer           :: n
  real              :: mu, sigma, FWHM
  real, allocatable :: x(:)

  ! read data from file. here we just set some values as an easy example
  x = [-2, 0, 5, -10, 3]

  ! estimator for mean value
  n  = size(x)
  mu = sum(x) / n

  ! estimator for standard deviation (biased estimator -> divide by (n-1) )
  sigma = sqrt(sum((x-mu)**2)/(n-1))

  ! full-width half maximum is simple scaling of standard deviation
  ! for Gaussian distribution
  FWHM = 2*sqrt(2*log(2.0)) * sigma
end program
jack
  • 1,658
  • 1
  • 7
  • 18
  • In Wikipedia they divide by `n` and not `n-1` in the standard deviation for discrete points calculation. – JAlex Mar 18 '21 at 18:56
  • 1
    @JAlex please post the wikipedia article (section) you are referring to. I am referreing to [Bessel's correction](https://en.wikipedia.org/wiki/Bessel%27s_correction). Also mentioned [here](https://en.wikipedia.org/wiki/Standard_deviation#Corrected_sample_standard_deviation). – jack Mar 18 '21 at 20:02
  • I forgot to mention that i already do that calculation. However need another way of calculating it. – Gundro Mar 19 '21 at 07:49
  • 1
    @Gundro Why? In which way different? You need to be specific to get some answer that will suit you. – Vladimir F Героям слава Mar 19 '21 at 08:21
  • @jack - https://en.wikipedia.org/wiki/Standard_deviation – JAlex Mar 19 '21 at 13:15
  • 1
    @JAlex I also linked to that page. See my previous comment. In the subsection "Corrected sample standard deviation" it explains the division by `n-1`. – jack Mar 19 '21 at 13:40