matlab - Calculating the area between two curves -


i have psd plot , trying calculate area between 2 curves in matlab 2 separate ranges of frequencies (8-30 hz , 70-100 hz). 1 area calculation per frequency range.

to calculate area between curves sections in each frequency range use:

r1=(f>=8 & f<=30); r2=(f>=70 & f<=100); arealf = trapz(f(r1),z(r1)-zm(r1)); areahf = trapz(f(r2),z(r2)-zm(r2)); 

f=frequency , zm, z represent z-scores of 2 conditions (normalized power).

i can calculate area between curves areas between curves in each frequency range, want calculate area in low frequency range when zm < z , when z > zm higher frequencies (the shaded regions in plot).

does have suggestion how this?

this plot showing areas trying calculate: enter image description here

if understand question correctly, need change logical masks being defined f being defined z , zm:

r1= zm < z; r2= z  < zm; area1 = trapz(f(r1),z(r1)-zm(r1)); area2 = trapz(f(r2),z(r2)-zm(r2)); 

for discontiguous blocks example posted, may need integrate on blocks one-by-one. case, threw code (i'm not sure if robust or if matlab has simple function perform task):

%   predicate mask    = zm < z;  %   determine index windows contiguous blocks. ind     = 1:numel(f); dmask   = xor(mask(1:end-1),mask(2:end)); iswitch = ind(dmask)+1; nswitch = nnz(dmask);  if mask(1) == true  % start true     ilo = [ind(1) , iswitch(2:2:end)];     ihi = iswitch(1:2:end)-1;      if mod(nswitch,2) == 0 %    end true         ihi = [ ihi , ind(end)];     end  else  % start false     ilo = iswitch(1:2:end);     ihi = iswitch(2:2:end)-1;      if mod(nswitch,2) ~= 0 %    end true         ihi = [ ihi , ind(end)];     end end nblocks = numel(ilo);   %   iterate on blocks total = 0; k = 1:nblocks;     mask  = ilo(k):ihi(k);     total = total + trapz(f(mask),z(mask) - zm(mask)); end 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

Redirect to a HTTPS version using .htaccess -