forked from JesseLu/objective-first
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathob1_calc_power.m
31 lines (21 loc) · 838 Bytes
/
ob1_calc_power.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function [Pout, err, filtered_percent] = ob1_calc_power(E, H, mode)
% Description
% Calculate power in an output mode. Assumes that all the power in the
% mode is propagating to the right (no reflections).
dims = size(E);
%
% Obtain magnitude of mode in both E and H fields.
%
Pout_0 = mean(sum(real(conj(E) .* H), 2)); % Calculate power in output mode.
E = my_project(mode.Ey, E); % Eliminate other modes from output field.
H = my_project(mode.Hz, H);
Pout = sum(real(conj(E) .* H), 2); % Calculate power in output mode.
err = std(Pout); % Calculate error.
Pout = mean(Pout);
filtered_percent = Pout / Pout_0;
function [f] = my_project(ref, field)
% Project y onto x.
my_dot = @(x, y) dot(y(:), x(:)/norm(x(:))) * x(:) / norm(x(:));
for k = 1 : size(field, 1)
f(k,:) = my_dot(ref, field(k,:));
end