numerical integration with borders

Hello everybody,
i have the spectral response data (xy) from a camera:
x: 451x1 double y: 451x1 double (red curve in the picture)
in front of the camera, I will mount an optical filter. This filter will only transmit light in a given range. For that purpose I want to integrate the spectral response curve of the camera (the xy Data)in the range of the filter. I've read about cumtrapz, but I don't know how to tell it to matlab, especially the borders.
Many thanks for your help.
Michael

回答(1 个)

One approach:
x = linspace(350, 1100, 2000); % Create Data
y = sin(2*pi*x/50) + 2; % Create Data
select = (x >= 600) & (x <= 650); % Create Data
xs = x(select);
ys = y(select);
int_select = cumtrapz(xs, ys); % Integrate
figure(1)
plot(x, y)
hold on
patch([xs fliplr(xs)], [zeros(size(ys)) fliplr(ys)], 'k')
hold off
grid
axis([min(x) max(x) 0 4])
text(625, 3.5, sprintf('Area = %.3f', int_select(end)))

2 个评论

Many Thanks for your answer. I expect after the integration just a value for the area in the given range under the curve. That's the code:
xi = x;
yi = response;
select = (xi>=611)&(xi<=645);
xs =xi(select);
ys =yi(select);
int_select = cumtrapz(xs,ys);
x and y have the dimensions 251x1 double
there is no error when I compile, the dimension and data type of select is 251x1 logical with the values 0. I have compiled Your code and there are some 1's in the middle.
int_select should give me only the area (last value in your script)? At the moment there is no value for int_select (0x1 double).
my x and y data are measured, that means that they are not linspaced.
Best regards,
Michael
My code worked with the data I created. I have no idea what the problem is with your getting an empty result.
One possibility could be the units your ‘xi’ data are in. You may want to check those, then create the ‘select’ limits to include the appropriate range.

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by