How do I plot wireless signal strength measurements using a spherical plot
6 views (last 30 days)
Show older comments
Hi,
I am completely new to using Matlab and have only started to look at it as I want a way to present wireless measurements taking from a wireless router. The router was kept at a set distance from the computer and was rotated by 360 degrees through the X and Y axis. Measurements where taken at 10 degree increments through each plane. I am having great trouble to understand the concept of how to plot these coordinates using Matlab.
Can anybody please help and point me in the right direction?
Thanks Mark
2 Comments
arich82
on 28 Jul 2015
Just to clarify--
Your data is sampled at every 10 degrees (so 36 samples around the circumference): does this mean you have 72 data points (36 around the X-plane equator, and 36 around the Y-plane prime meridian), or do you have 1296 samples (36 rings of 36 data points each)?
Note: sph2cart might prove helpful; scatter3 or surf might be useful if you want 3-D visualization.
Answers (3)
arich82
on 29 Jul 2015
Edited: arich82
on 29 Jul 2015
[Edited for grammar.]
Sorry for the delayed reply: I typed this up yesterday afternoon, but got called away before I could post it.
I'm afraid I might have misled you with my question. With 10 degree spacing, you should have 18 rings with 36 samples each; otherwise, half your data points would be duplicates (possible, but unlikely).
You can make a wire plot as you described using plot3, though it takes a little finessing since Matlab uses phi as elevation from the x-axis instead of z-, and ultimately, might not be very useful.
I'll construct some dummy data and show three plot types you might wish to consider.
dtr = pi/180;
th = [0:10:180].'*dtr;
phi = [0:10:360].'*dtr + 90*dtr; % add 90 degrees so lines start at top of sphere
r = 1;
[TH, PHI, R] = meshgrid(th, phi, r);
% function for dummy data
f = @(th, phi, r) r.*sin(2*th).*cos(4*phi);
data = f(TH, PHI, R);
meshgrid takes the vectors specified by theta, phi, and r and creates 3-D arrays, suitable for plotting; however, since r only has a single value equal to one, the arrays are equivalent to matrices, i.e. m-by-n-by-1. Also, since Matlab's version of spherical coordinates uses phi to denote elevation from the x-axis, not the z-axis, we've added 90-degrees to phi to better replicate your example plot.
(Note that I'm assuming you already have data, so you won't need to define the anonymous function f, and that your data is in the form of a 36-by-18 matrix; my examples are size 37-by-19, because I've duplicated the point at the pole [this is to prevent holes in the surface plot]; you might need to pad your data using something like data = [data(end, :); data]; data = [data(:, end), data];, which prepends the original matrix with its own last column and row.)
Note that the data is in spherical coordinates, but Matlab can really only plot cartesian in 3-D. To generate the plot data, we can use sph2cart:
[X, Y, Z] = sph2cart(TH, PHI, R);
The first method we'll look at uses plot3 and recreates the wireframe you showed. Unfortunately, the entire line object must be a solid color (unless the newer version of Matlab has added a new feature), so it won't be terribly useful for displaying the intensity.
figure;
axes;
plot3(X(:), Y(:), Z(:));
You can add some formatting to make it look more like your example (search the help docs to understand what these commands are doing):
grid('on')
set(gca, 'Ztick', [])
set(gca, 'XMinorGrid', 'on')
set(gca, 'YMinorGrid', 'on')
axis('equal');
axis('square');
xlabel('x')
ylabel('y')
zlabel('z')
title('plot3')
The above reasonably reproduces your example, but isn't terribly useful since it doesn't make use of the data.
To plot just the data points you actually measured, try scatter3:
figure;
axes;
scatter3(X(:), Y(:), Z(:), 15, data(:), 'filled'); % colon converts matrix to vector
% formatting boiler plate
grid('on')
set(gca, 'Ztick', [])
set(gca, 'XMinorGrid', 'on')
set(gca, 'YMinorGrid', 'on')
axis('equal');
axis('square');
xlabel('x')
ylabel('y')
zlabel('z')
title('scatter3')
Finally, consider using a surface plot:
figure;
axes;
surf(X, Y, Z, data);
% formatting boiler plate
grid('on')
set(gca, 'Ztick', [])
set(gca, 'XMinorGrid', 'on')
set(gca, 'YMinorGrid', 'on')
axis('equal');
axis('square');
xlabel('x')
ylabel('y')
zlabel('z')
title('surf')
If you want, you can use shading to interpolate the data, instead of the having a patch-work quilt, but interpolation may introduce artifacts into the representation of your data:
shading('interp')
There's a lot of options above. Search the help docs for anything you don't understand, and feel free to ask another question if you're struggling with anything. (And please accept this answer if it helps.)
4 Comments
arich82
on 30 Jul 2015
For the surface plot, the units on data don't really matter (though they will affect how well the colorbar is used); data is just used to index the color of the surface plot, and doesn't affect the spatial dimensions. Do you want some other unit than dB?
Assuming your data is in a matrix, just rename that matrix data and delete the two lines above where I constructed the dummy data, and the above code should get you a preliminary plot. (Note that you might need to resize th and phi depending on the actual number of data points you have.)
If it's not in a matrix, then you'll have to describe what you have/want a little more precisely.
(Note: It is possible to attach data files to these posts. Assuming you have the data loaded in Matlab, you can save the workspace data to a .mat file and post it; if we knew the exact format of your data, it might make it easier to understand your difficulty in adapting the above code.)
P.S.-- If you prefer Walter's mesh plot, you could directly replace surf with mesh in the original post. Equivalently, you could use hc = get(gca, 'Children'); set(hc, 'FacetColor', [1, 1, 1], 'EdgeColor', 'flat') to make a surf look like a mesh.
Muthu Annamalai
on 28 Jul 2015
You may try to plot the polar plots for X-Y, X-Z, and Y-Z planes, and choose to use decibel (dB) scale or log scale. Read more via,
>> doc polar
>> doc plot3
See Also
Categories
Find more on Polar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!