matlabareanumerical-integration

integrate between curves


Here is a plot with 2 trends on it:

enter image description here

I want to find the area under the black curve (the black lines are all part of one trend), but above the blue curve.

%w = wavelength array, Tf = filter Transmission, Ts = spectrum Transmission
figure
plot(w,Tf,'b')
hold on
plot(w,Ts,'k')

Solution

  • Select the part of the black line (Ts) that lies above the blue line (Tf) and integrate (trapz):

    d = max(Ts-Tf,0); % or max(Tf,Ts)-Tf;  % thanks, matheburg!
    trapz(w,d)