tags:

views:

53

answers:

1

I have a very simple problem.

Suppose we have the following code to calculate directivity of isotropic antenna.

ThDeg = 0:5:180; 
dtheta = 5*pi/180;
dphi = 5*pi/180;
Th = ThDeg*pi/180;

% the above are the angles at which the following matrix is acquired in practical case. In this case we take a matrix of all ones.

U_iso = ones(72, 37); % our matrix assumed

omega_iso = 0;
for i = 1:72
    for j=1:37
        omega_iso = omega_iso + U_iso(i,j)*sin(Th(j))*dphi*dtheta;
    end
end

D_iso = 4*pi/omega_iso

This is correct code which gives a value very close to 1 which should be for an isotropic antenna. Its just a sanity check so that when we have the actual matrix of 72*37, we can confirm that our code is correct.

Now the problem is that in the above example, we took a 72*37 matrix and did our integral approximation and got ONE value of directivity.

What I need is to calculate directivity at every cell value of the 72*37 matrix. So the result would be another 72*37 matrix showing the calculated value of directivity at each cell value( which in this ideal case is 1). So for this example, currently we are getting the result as only one value of directivity. We need this value at every cell of the U_iso matrix. This would result in a 72*37 matrix with same value in it. Moreover, all values in the matrix would be same as the result from the above code.

So can you help me in this. I cant understand how to move the loop accross the matrix. So it calculates for each cell.

Awaiting reply.

A: 
SinThJ = zeros(72, 37);

% For each of the 72 x 37 cell, compute sin(Th(j))

for j = 1:37
  SinThJ(:, j) = repmat( sin(Th(j)), 72, 1);
end

% Elementwise multiplication
% This omega_iso becomes a matrix

omega_iso = U_iso .* SinThJ * dphi * dtheta;

% This is the integration of the matrix

omega_iso_sum = sum(sum(omega_iso));
rwong

related questions