MATLAB phased.URA.step: where is my phaseshift? - matlab

I want to get the sensor array complex response ratios from an angle. I try to use phased.URA() and its method step(freq, angle), but it gives me equal numbers for each element for any angle. Where is my phaseshift, dudes?
Here is a small example:
ant_array = phased.URA();
disp(ant_array.step(3e8, [45; 0]));
It gives me a result:
1
1
1
1
Can anyone tell me, what does it mean and how can I use angle parameter correctly?

Related

To calculate the length of a curve on the image

Given the data of the curve and the size of the image, how to calculate the length of the curve ?
curve = [9.93,4;9.87,4.10;9.80,4.20;9.74,4.30;9.68,4.40;9.63,4.50;9.59,4.60;9.55,4.70;9.53,4.80;9.51,4.90;9.50,5;9.50,5.10;9.51,5.20;9.48,5.30;9.55,5.40;9.45,5.47;9.55,5.52;9.45,5.59;9.55,5.65;9.45,5.72;9.55,5.77;9.45,5.84;9.55,5.90];
backgroud = ones(20,20);
imshow(backgroud)
hold on, plot(curve(2,:),curve(1,:),'r');
To expand on the comment, you can simply sum the lengths of the line segments that make up the curve. This could be accomplished using the following code.
curve = [9.93,4;9.87,4.10;9.80,4.20;9.74,4.30;9.68,4.40;9.63,4.50;9.59,4.60;9.55,4.70;9.53,4.80;9.51,4.90;9.50,5;9.50,5.10;9.51,5.20;9.48,5.30;9.55,5.40;9.45,5.47;9.55,5.52;9.45,5.59;9.55,5.65;9.45,5.72;9.55,5.77;9.45,5.84;9.55,5.90];
len = sum(sqrt(sum(diff(curve).^2,2)))
result
len =
2.4757
Edit: As beaker pointed out, the indices are backwards in your answer. Take a look at the values of curve_x1, curve_x2, etc... and you will see that they are just a single value. If you reverse the indices we get the same result. Also, as a sanity check take a look at the plot of the curve, it spans about 2 units in the first dimension and about 0.4 units in the second dimension so a number near 2.5 seems reasonable, a number like around 8 is much too large.
curve_x1 = num2cell(curve(1:end-1,1));
curve_y1 = num2cell(curve(1:end-1,2));
curve_x2 = num2cell(curve(2:end,1));
curve_y2 = num2cell(curve(2:end,2));
instance_length = cellfun(#(x1,y1,x2,y2) sqrt((x2-x1)^2+(y2-y1)^2), curve_x1,curve_y1,curve_x2,curve_y2);
distance = sum(instance_length)

Rotation matrix in Matlab

I am going to rotate from one frame to another one with rotation matrix. goal of program is to make my Gyro parallel to earth, it means output vector should has first two numbers zero and third one -9.81.
Codes:
vs1 = 1;
vs2 = -0.003;
vs3 = -9.808;
vst = [vs1 vs2 vs3]';
alpha = (acosd(vs1/sqrt(vs1^2+vs2^2)));
gama = (acosd(vs2/sqrt(vs1^2+vs2^2)));
beta = (acosd(vs3/sqrt(vs1^2+vs2^2+vs3^2)));
R1 = [(cosd(gama)*cosd(beta)*cosd(alpha))-(sind(gama)*sind(alpha)) (cosd(gama)*cosd(beta)*sind(al)+sind(gama)*cosd(al)) (-cosd(gama)*sind(beta));((-sind(gama)*cosd(beta)*cosd(alpha))-cosd(gama)*sind(alpha)) ((-sind(gama)*cosd(beta)*sind(alpha))+(cosd(gama)*cosd(alpha))) sind(gama)*sind(beta);sind(beta)*cosd(alpha) sind(beta)*sind(alpha) cosd(beta)];
disp (R1*vst)
result for vs1,vs2 and vs3 is : -0.00599, 0.0000359 and 9.858845622079866. first, I can not understand why program give me positive Z and why it does not make first two numbers zero?
thanks in advance
You have a bug in your code. There are two places where I think the variable "al" should actually be "alpha" if I'm following your code correctly.
But your code also generates alpha = 90 and gama = 180 for those inputs. All you're going to do is flip the axes to within machine precision with those inputs, so it's not going to achieve the results you're looking for.
1) Are you sure the input vector is correct? Why would gravity have a value near X=1 if you're nearly vertical (Z = -9.808)?

Using Negative Values in Matlab

In order to find best fit (thru polyfit), i am getting negative p value but matlab is not accepting it (Subscript indices must either be real positive integers or logicals.). Is there any way that I can use it ? I can't think of alternative method. I'll always get negative values.
EDIT:
I am trying to flattening baseline of a curve, for that. I am running for loop to have fit from 1 to 3 order. And then I am using smallest normr s value to to find the best fit and then subtract it from the whole curve to get baseline straight. I tried with few curves it works well but not with all of the data because of above describes issue.
part of the code I am working on:
for i=1:3
[p,s]=polyfit(x,y,i);
a=s.normr;
b(i,1)=p(1);
normr(i,1)=a;
ind=find(b==min(b));
mn=b(ind,1);
Yflat=y-mn(1)*(x-mean(x));
ca{2,2}=Yflat;
clear a b normr p s rte ind ind2 Yflat
end
When I translate an image into negative coordinates,
I usually record an offset e.g.
offset = [ -5, -8.5 ]
and save the intensity values in matrix begin with (1, 1) as usual,
But when comes to calculation, let the coordinates array add up with the offset
e.g. [ actualX, actualY ] = [ x, y ] + offset ;
It may need extra efforts, but it works.
Good Luck!
The code below (your code from the comments + initialization of x, y) executes. What is the problem?
x = 1:50;
y = randn(size(x));
for i=1:3
[p,s]=polyfit(x,y,i);
a=s.normr;
b(i,1)=p(1);
normr(i,1)=a;
ind=find(b==min(b));
mn=b(ind,1);
Yflat=y-mn(1)*(x-mean(x));
ca{2,2}=Yflat;
end

matlab diagonal code

tesconf is 3x3 matrix;
tes_avg = (diag(tesconf)./sum(tesconf,2));
example that the result of tes_avg is given [0.345;0.3423;0.483]
However, i wish to get average result of this 3 values, how should i change the code above?Please advise...
Simply avg = mean(tes_avg); (or directly tes_avg = mean(diag(tesconf)./sum(tesconf,2));).

Matlab "interp2" problem regarding NaN at edges

I am a bit stuck on a simple exercise and would appreciate some help.
I am trying to do some simple 2D interpolation using the "interp2" function in Matlab for a variable 'tmin' of dimension [15x12]:
lat = 15:1.5:32;
lon = 70:1.5:92;
lat_interp = 15:1:32;
lon_interp = 70:1:92;
[X,Y] = meshgrid(lat,lon);
[Xi,Yi] = meshgrid(lat_interp,lon_interp);
tmin_interp = zeros(length(lon_interp),length(lat_interp),Num_Days);
tmin_interp(:,:) = interp2(X,Y,tmin(:,:),Xi,Yi,'linear');
This code results in the last row and last column of tmin_interp to be NaNs, i.e.:
tmin_interp(23,1:18) ==> NaN
tmin_interp(1:23,18) ==> NaN
Does anyone know what I might be doing wrong? Am I making a simple mistake with regards to the interpolation setup? Thank you for your time.
The reason they are nans is that there is no data before and after your grid to interpolate to. Linear interpolation uses the gradient of the field at the Xi,Yi, in order to estimate the value at that point. If there is nothing either side, it can't.
You can use extrapval parameter to extrapolate outside the X,Y you specify. Just add the parameter 0 after 'linear':
interp2(X,Y,tmin(:,:),Xi,Yi,'linear', 0);
This will put zero for the points 'on the edge'. However, it is likely that for points outside, they may fall off to some default value, like zero. To do this, you can add zeros before and after tmin:
tmin_padded = [ zeros(1,size(tmin,2)+2)
zeros(size(tmin,1),1) tmin zeros(size(tmin,1),1)
zeros(1,size(tmin,2)+2) ];
(haven't checked this but you get the idea.) you will also need to add some pre- and post-values to X and Y.
Use some other value, if that's the 'outside' or 'default' value of tmin.
PS why are you creating tmin_interp as 3-dimensional?
Or just try:
interp2(X,Y,tmin(:,:),Xi,Yi,'spline');
to avoid imposing the 0 value.
HTH!