Generating Radio propagation pattern in matlab? - matlab

I want to implement a part of article. The following explanations are expressed in it.
"we evaluate the performance of proposed localization method at varying degree of irregularity, where DOI defines the radio propagation irregularity per unit degree change in direction. The radio propagation irregularity model used in this paper is shown as follows:"
I have tried to write the code of this part but It doesn't work and can't get a result.
function Coeff=k(i)
Rand=rand(1,100);
DOI=0.02;
if(i==0)
Coeff=1; %Terminating condition
else
while i<360
Coeff=k(i-1)+Rand*DOI; %DOI=[0.01,0.02,0.03,0.04,0.05]
end
end
end
And The following figure has been shown in that article for DOI=0.02...I need to get an output like this, How can I do it
Thanks in advance.

It would help if you post a link to the article, but in this case they just generate a circular path with some noise.
DOI=0.05;
phi = linspace(0,2*pi,360); %360 angles
r=-DOI+2*DOI*rand([1,360]); %random values between -DOI and DOI
r=cumsum(r)+1; %add them to make a path, with mean value 1
while abs(r(end)-r(1))> DOI %start and finish must not be too far away from eachother
r=-DOI+2*DOI*rand([1,360]);
r=cumsum(r)+1;
end
plot(r.*cos(phi),r.*sin(phi),'r',cos(phi),sin(phi),'--b')
axis equal

Related

How to calculate Gradient in matlab?

I am working on pedestrian step detection (acceleration). I want to calculate statistical features from my filtered signal. I have already calculated some and now I want to calculate gradient.
My data is of 1x37205 double. I calculated features using for loop with moving window size=2samples and 50% overlap of previous window. Below I am attaching the code I tried to calculate the gradient.
I am not sure if it is the right way to calculate or not? In addition, I am also unable to understand that what is the purpose to use gradient, how it can be useful for step detection and how to work with gradient? Could some one guide me or provide any code help in matlab?
%%Here M is mean and V is variance i already calculated from filtered data
G = zeros(length(window:length(M)), 2);
for i = window:length(M)
temp = gradient(M(i+1-window:i),V(i+1-window:i));
G(i, 1) = temp(2, 1); % "c1"
G(i, 2) = temp(2, 1); % "c2"
end
One of the best features of Matlab is its documentation. If you are unfamiliar on how to get specific function documentation, enter the following in the command line:
doc functionName
Alternatively, for 'brief' documentation that displays in the command line, you can enter:
help functionName
Also see the documentation link here.
Your question is worded poorly, so I will summarize what I understand and answer accordingly:
You have a step detection data (1*37205) double, let us call it stepSignal
stepSignal is position data
You want your window to be 2 steps with 50% overlap. This is the default behavior for the gradient function.
You do not need a "for" loop to achieve your goal. According to the documentation, "gradient" can take one input.
See the code below, and if need be add clarifications to the original question.
%% Assume that stepSignal is already imported into the workspace
velocity = gradient(stepSignal);
One last note, when you give "gradient" two inputs, it automatically assumes the second input is a uniform spacing value.

least mean square filter to reduce noise in image?

I have a reference image and output image which is having lot of noise.I created a mask for a portion in both images.I wanna design a filter which when applied to this region,can be applied to whole region.i am using least mean square method to reduce noise.But each time the mean square keeps increasing.Any idea how to sort out this problem.I am using MAT LAB to do this.Here is my code.
output=double(imread('obtained_output.jpg'));
reference=double(imread('reference_output.jpg'));
[M,N]=size(output);
upper_mask_obtained = output(1:100, 1:100);
lower_mask_obtained=output(201:300,1:100);
total_mask_obtained=[upper_mask_obtained;lower_mask_obtained];
upper_mask_reference = reference(1:100, 1:100);
lower_mask_reference=reference(201:300,1:100);
total_mask_reference=[upper_mask_reference;lower_mask_reference];
Ns=5;
[a,b]=size(total_mask_reference);
u=.000000001;
W=ones(Ns,Ns);
Y=zeros(Ns,Ns);
DD=zeros(Ns,Ns);
error=zeros(M,N);
e=zeros(Ns,Ns);
error_mask=abs(total_mask_obtained-total_mask_reference);
s= sum(sum(error_mask.^2));
mean_square_error=(s/(a*b));
while(mean_square_error>7)
for m=1+Ns:200
for n=1+Ns:100
for l=1:Ns
for k=1:Ns
Y(l,k)=total_mask_obtained(m-Ns+l-1,n-Ns+k-1);
DD(l,k)=total_mask_reference(m-Ns+l-1,n-Ns+k-1);
end
end
Z=conv2(Y,W,'same')/sum(sum(W));
e=DD(3,3)-Z(3,3);
W=(W+u*e*Y);
total_mask_obtained(m-Ns+2,n-Ns+2)=Z(3,3);
end
end
error=total_mask_reference-total_mask_obtained;
mean_square_error=sum(sum(error.^2))/(a*b);
end
figure(2);
final_output=(conv2(output,W,'same')/(sum(sum(W))));
imshow(uint8(final_output));
I think your task could be well-accomplished by using Gaussian filter. It is already built-in in Matlab. http://www.mathworks.com/help/images/ref/fspecial.html Check this for your reference. Sorry I'm new in StackOverflow. So I can't add comments yet. Sorry if it is not answer to your question.

Matlab: Issues with filling a 401x401 matrix

I'm having an issue with filling a 401x401 matrix. I know exactly what I want to do but I'm struggling to implement it.
I would like for a specific angle (y axis from 30-70) and a specific wavelength (x axis from 400nm-1000nm) the matrix is filled to 401 x 401 to contain the associated reflection coefficient (I have the equations and they're all good).
I thought this would work#
for i=1:length(ANGLE)
angle=ANGLE(i);
etc etc
for i=1:length(wavelengths)
lambda=wavelengths(i);
etc etc
REF(i)=ref;
end
end
I hope you can help, sorry if this is badly worded.
Thanks
Carmel
As m_power pointed out, you should use a different iterator for the internal for loop (and also try to avoid using i and j, as they are commonly used to represent imaginary values). In addition to this, you should reference both a row and column entry for each reflection coefficient entry. Since you want angle in the vertical direction and wavelength in the horizontal direction, you could use something like this:
for ii=1:length(ANGLE)
angle=ANGLE(ii);
etc etc
for jj=1:length(wavelengths)
lambda=wavelengths(jj);
etc etc
REF(ii,jj)=ref;
end
end
Hope this helps.

what values should i pass to the normalization function in iris recognition?

i've been working on implementation for iris recognition system in Matlab ,
on Normalization i used this function
[polar_array, polar_noise] = normaliseiris(image, x_iris, y_iris, r_iris,x_pupil, y_pupil, r_pupil, eyeimage_filename, radpixels, angulardiv);
i passed x, y and radius coordinates for both circles (iris and pupil) to x_iris, y_iris, r_iris,x_pupil, y_pupil, r_pupil
but i'm stuck at these two variables (radpixels, angulardiv) !!
couldn't figure out what values should i pass ?!
i saw someone said he/she passed 32 , 240 respectively but it didn't work with me !
Can anyone tell me what values should i pass ? or at least an explanation ?
Thanks :)
Isn't it clearly said in the comments?
% radpixels - radial resolution, defines vertical dimension of
% normalised representation
% angulardiv - angular resolution, defines horizontal dimension
% of normalised representation
(Source)
Note: "32, 240" can be useful values... but how shall we know what's wrong with your parametrization without more details? You should think about how much radpixels and angulardiv are useful for your application.

problem im motion control with MATLAB

i have a problem in motion control in matlab
imagine a four bar linkage mechanism like this.as you you know in an ordinary 4 bar linkage we have 2 fix points but here we have just one & the second one it fixed to a pinion (small gear).we have the ratio of gears so we have a relation between teta1 & teta2
teta2 = 5*teta1 (the mechanism can rotate in the first fix point)
i used to write this code for motion control but the when i run it the graphs are not correct (because they should be something linke sin or cos graph)
d(n) is a auxiliry vector for solving equations
please ask if you have further questions
this is the code :
clc,
close all,
clear all,
ax=0;
ay=0;
r1=12;
r2=7;
r3=9;
r4=5;
n=0;
for teta1=0:pi/180:2*pi
n=n+1;
D = r1*exp(i*teta1)-r2*exp(i*5*teta1);
tetad(n) = angle(D);
d(n) = abs(D);
landa(n)=acos((d(n)^2+(r3)^2-(r4)^2)/(2*d(n)*r3));
alfa(n)=acos((d(n)^2+(r4)^2-(r3)^2)/(2*d(n)*r4));
teta3(n)=landa(n)+tetad(n);
teta4(n)=(+pi-alfa(n)+tetad(n));
end
aa(n)=teta1*180/pi;
hh(n)=tetad(n)*180/pi;
bb(n)=landa(n)*180/pi;
cc(n)=alfa(n)*180/pi;
nn(n)=teta3(n)*180/pi;
dd(n)=5*teta1*180/pi;
ee(n)=teta4(n)*180/pi;
figure(1),plot(aa,hh),xlabel('teta1'),ylabel('tetad');
figure(2),plot(aa,d),xlabel('teta1'),ylabel('d');
figure(3),plot(aa,bb),xlabel('teta1'),ylabel('landa');
figure(4),plot(aa,cc),xlabel('teta1'),ylabel('alfa');
figure(5),plot(aa,nn),xlabel('teta1'),ylabel('teta3');
figure(6),plot(aa,dd),xlabel('teta1'),ylabel('5*teta1');
figure(7),plot(aa,ee),xlabel('teta1'),ylabel('teta4');
I have no idea what you are trying to solve here, but probably you want to move the end of your for-loop a few lines down, so the vectors you plot contain all values and not only the last one.