Thursday, 22 December 2016

Polar plot in Gnuplot

I was recently playing with microphone array polar diversity responses and did a search for suitable Gnuplot polar plot solutions. There are a number that turned up but none of them really matched my requirement so here it is :

set polar
set angle degree
set size ratio 1
set tmargin 3
set bmargin 3
set title "Microphone Polar Diversity Response : Mic Spacing 0.1 (meters)"
set key out vert nobox

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

unset border
unset xtics
unset ytics

f_maxGain=0.                                    # Maximum gain - MUST BE FLOATING POINT
minGain=-80                                     # Minimum gain - MUST BE INTEGER
tickstep = 10                                   # Ticks every 10 dB
numticks = 8                                    # numticks = r / tickstep :: Don't use divide because numticks is used in for loop and doesn't work
f_numticks = 8.                                 # Floating point numticks


set rrange [minGain:0]
set rtics tickstep format '' scale 0

set label '0°' center at first 0, first -minGain*1.05
set label '90°' right at first -minGain*1.05, 0
set label '180°' center at first 0, first minGain*1.05
set label '270°' left at first minGain*1.05, 0

set for [i=.1:numticks] label at first minGain*0.001, first minGain*((i/f_numticks) + 0.007) sprintf("%d dB", minGain+(i*10))
unset raxis

plot "250.dat" u (-$1+90.):($2-f_maxGain) t "250 Hz" w lines lc rgb "magenta", \
      "500.dat" u (-$1+90.):($2-f_maxGain) t "500 Hz" w lines lc rgb "red", \
      "1000.dat" u (-$1+90.):($2-f_maxGain) t "1000 Hz" w lines lc rgb "blue", \
      "2000.dat" u (-$1+90.):($2-f_maxGain) t "2000 Hz" w lines lc rgb "cyan", \
      "4000.dat" u (-$1+90.):($2-f_maxGain) t "4000 Hz" w lines lc rgb "orange"

print "Hit <CR> to continue ..."
pause -1

The data was generated in a C program and written to the .dat files, then I just used gnuplot on the command line to execute the script and plot the results.

The data files look like this (i.e. two columns : angle and gain) :

# Antenna Beam Pattern
# Angle Gain
-9.00e+01 -1.17e+00
-8.90e+01 -1.17e+00
-8.80e+01 -1.17e+00
.
.

Here is the plot for 100 mm mic spacing :


The gnuplot script allows the min and max gain values to be changed.

If you have found this solution useful then please do hit the Google (+1) button so that others may be able to find it as well.
Numerix-DSP Libraries : http://www.numerix-dsp.com/eval/

2 comments:

  1. Good article.Thank you for providing this informative article.I read full content and i can follow all the information provided here.This article helped me in a great extent.This is really interesting to read this.Visit best essay writing service to get more details.

    ReplyDelete
  2. Thank you for the script.
    With small changes I'm using it for antenna pattern.
    Pascal

    ReplyDelete