MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: PolarPlot in dB

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107529] Re: PolarPlot in dB
  • From: dr DanW <dmaxwarren at gmail.com>
  • Date: Tue, 16 Feb 2010 03:51:54 -0500 (EST)
  • References: <hlb8ou$rk9$1@smc.vnet.net>

Marc,
Below is a .m file I created for doing polar patterns of hearing aid
directionality.  The scale for hearing aid directionality is set by a
standard, so the limits are hard-coded; I did not try to make it
general.  The scale goes from +5 dB to -25 dB, with everything below
-25dB truncated off.  The standard also defines 0 degrees to be
vertical on the page and azimuth increasing clockwise, so there are
some functions to make this transformation which may not be necessary
for you.

Enjoy
--- snip ---

KEAxisColor::"usage"="KEAxisColor is the color I like for axes.";


KEAxisColor=RGBColor[112./255,120./255,68./255];


microphonePolarGrid=Module[{a,xy},
a=Range[0,330,30];
xy={Sin[#],Cos[#]}&/@(a Degree);
Flatten[{
KEAxisColor,
Line[{{-1,0},{1,0}}],Line[{{0,-1},{0,1}}],
Circle[{0,0},#]&/@{10,15,20,30},
Line[{5#,30#}]&/@xy,
Black,
Circle[{0,0},25],
MapThread[Text[ToString[#1]<>"\[Degree]",32.5#2]&,{a,xy},1],
Text[Framed[ToString[#]<>" dB",FrameStyle->White,FrameMargins-
>1,Background->GrayLevel[.99]],{4,(#+25)}]&/@Range[-20,5,5]
}]
];


originLimit=Function[v,If[v<-25,0,v+25],Listable];


PolarPatternFunction::"usage"="PolarPatternFunction[ \!\(\*
StyleBox[\"fnc\",\nFontSlant->\"Italic\"]\) ] accepts a linear polar
response function \!\(\*
StyleBox[\"fnc\",\nFontSlant->\"Italic\"]\) as a function of theta in
radians, and returns the polar pattern function in dB re \!\(\*
StyleBox[\"fnc\",\nFontSlant->\"Italic\"]\)[0] as a function of
azimuth in degrees.";


PolarPatternFunction[prf_,th_Symbol]:=Function[az,Evaluate[
N[20Log[10,Abs[(prf/.th->(360-az)Degree)/(prf/.th->0)]]]
]
]


PolarPatternFunction[prf_]:=Function[az,Evaluate[
N[20Log[10,Abs[prf[(360-az)Degree]/prf[0]]]]
]
]


MicrophonePolarPlot::"usage"="MicrophonePolarPlot[ ppf, {az, min,
max} ] plots the polar pattern function as a function of azimuth az
from min to max. \n\n Note that polar pattern must be normalized for
it to display correctly on the grid.  Functions created by
PolarPatternFunction are normalized.";


Options[MicrophonePolarPlot]:=Options[PolarPlot];


MicrophonePolarPlot[pp_,{azs_,azmin_,azmax_},opts:OptionsPattern[]]:=
PolarPlot[
Evaluate[Sequence@@Module[{q},{
originLimit[pp]/.azs->(\[Pi]/2.-q)/ Degree,{q,\[Pi]/2-azmax Degree,\
[Pi]/2-azmin Degree}}]],
opts,
AspectRatio->1,
PlotStyle->Thick,
PlotRange->{{-35,35},{-35,35}},
Axes->False,
ImageSize->Medium,
Prolog->microphonePolarGrid
]


AzimuthToTheta::"usage"="AzimuthToTheta[ az ] converts azimuth to
theta.  A convenience when generating simulated data from a polar
response function, as in 20*Log[10, Abs[R[AzimuthToTheta[az]]]]";


AzimuthToTheta[az_]:=(360-az)Degree


NormalizePolarData::"usage"="NormalizePolarData[ dat ] normalizes dat,
a data set in the format { {azimuth, dB}, .. } to the value of the
first data point, assumed to be azimuth = 0.  Pass a second argument
to normalize to that value.";


NormalizePolarData[dat_,ref_:Automatic]:=Module[{r},
r=If[ref===Automatic,dat[[1,2]],ref];
{#[[1]],#[[2]]-r}&/@dat
]


ListMicrophonePolarPlot::"usage"="ListMicrophonePolarPlot[ ppd ] plots
polar pattern data in the format { {azimuth, dB}, .. }.  \n\n Note
that polar pattern data must be normalized for it to display correctly
on the grid.  Use NormalizePolarData to do so.";

---end code---


  • Prev by Date: Re: need help determined time to travel a path
  • Next by Date: Re: Shadow error when trying to use ParallelTable
  • Previous by thread: Re: PolarPlot in dB
  • Next by thread: (-1)^(1/2.) on Mathematica!