Lrrrence
Lrrrence

Reputation: 23

Creating a microphone polar pattern plot in gnuplot

I would like to create a microphone polar pattern plot that has a scale of -20 (in the center) out to +5 in steps of 5. I have found similar code but nothing that allows for the scales to be negative.
Multiple patterns will then need to added to the plot covering a few different frequencies, I have degree values (0-360) and corresponding dB values (-25 - +5).

This is what the plot should look like (though with slightly different scales):

polar_pattern_plot

The closest gnuplot I have found to this is here: How to get a radial(polar) plot using gnu plot?

Perhaps this could be modified to suit my needs?

I would also like 0 degrees to be found at the top of the plot rather than on the right.

I am new to using gnuplot so I am not particularly familiar with its code, therefore it has been difficult for me to modify the code with any great success (so far anyway).

Upvotes: 1

Views: 2766

Answers (2)

Hans Albertsson
Hans Albertsson

Reputation: 11

Unfortunately Christoph's answer is wrong.

You can see that if you check where the plot curve crosses the 5db circle.

What should be plotted is

20*log10(A+B*cos(t)) 

where A+B = 1 and A - B determines the (nominal) directivity pattern.

The first diagram seems to be for A=B=0.5 which makes for a cardioid pattern.

Upvotes: 1

Christoph
Christoph

Reputation: 48390

So you want to plot a polar function, e.g. r(theta) = 1 + sin(theta).

Plotting the function is quite easy, just do

set polar
plot 1+sin(t)

A simple polar grid can be plotted with

set grid polar

but that has the raxis and the rtics on a different position than where you wanted. It is not problem to specify custom labels. But angular labels aren't supported, so you need to set them manually. And the border and the other axes and tics must be unset.

To get the very same image as you showed, use the following script:

set terminal pngcairo size 700,600 font ',10'
set output 'cardioid.png'

set angle degree
set polar
set size ratio 1
set tmargin 3
set bmargin 3

set style line 11 lc rgb 'gray80' lt -1
set grid polar ls 11

unset border
unset xtics
unset ytics

r=1
set rrange [0:r]
set rtics 0.166 format '' scale 0
set label '0°' center at first 0, first r*1.05
set label '180°' center at first 0, first -r*1.05
set label '90°' right at first -r*1.05, 0
set label '270°' left at first r*1.05, 0

set for [i=1:5] label at first r*0.02, first r*((i/6.0) + 0.03) sprintf("%d dB", -30+(i*5))
unset raxis

plot 0.5*(1+sin(t)) linewidth 2 t ''

With the result:

enter image description here

That includes some offsets for the labels, which depend on the terminal, the canvas size and the font size. So you may need to adapt them.

I had to increase the top and bottom margins a bit (here by 3 character heights) in order to have enough space for the angular labels. They aren't included in the automatic margin calculations, because the don't belong to an axis.

Upvotes: 1

Related Questions