Simple beam pattern in Python
It’s been a long time since I’ve
(a) used Python, numpy, scipy, or matplotlib
(b) done a beam pattern calculation of any kind
So I thought it would be a good chance to brush up on several things all at once, and maybe even have the satisfaction of making a pretty picture at the end of the night.
Well, here’s the (perhaps not so) pretty picture:
This was so simple, I’m almost embarrassed to post it, but it will probably be helpful for me later, so here it is. What is it? I pretended I had two little pingers spaced 5 wavelengths apart, sending out continuous sinusoidal waves. I summed these signals at each of the elements in a 2-D grid, plotted the resulting magnitudes, and voila.
What I had to learn:
- How to use exp() using numpy – I had to load it separately for some reason, otherwise it would default to the exp() that comes with the basic math package, which doesn’t allow computations on arrays.
-How to plot an image, a la “imagesc” in Matlab. This is accomplished using <code>imshow(datahere)</code>, and a colorbar can be added using <code>colorbar()</code>.
-How to do a screen capture of a certain area on a Mac computer: command+shift+4 gives you crosshairs so you can pick what you like.
It would have been nice to add some attenuation, but I’m too tired now. One more thing that I need to figure out though, what’s the best way to post my code? I probably should figure out how to put it up on the bluehost server (where this blog lives), and link to it from here.
