Search code examples
matlabplotpolar-coordinates

Something strange using polar plot function in MATLAB


I have a simple function of theta and I want to plot this function in dB using the polarplot function in MATLAB. But when I make the graph from -40 to 0, the graph seems to have a strange part around horizontal axis. My MATLAB code (R2016a) is:

%% Define range of plotting angle.
ceta= [10^-9:0.0001:2*pi];
% ceta starts not from pure zero to avoid 0/0 in some cases.

E =  abs( ( cos((cos(ceta))*pi/2) ) ./ ( sin(ceta) ) ); 

power_dB = 10.*log10(E.^2); 
power_dB = power_dB - max(power_dB);
max(power_dB)
polarplot(ceta,power_dB);
rlim([-40 0]); 

The obtained figure is this: plot resulting from code


Solution

  • Your values for E are very near to 0 when ceta = 0, pi, or 2pi. This is resulting in very large values when you take the log of E.

    You can just remove the points from ceta and E when E is very low. See the code block below.

    E =  abs( (  cos((cos(ceta))*pi/2) ) ./ ( sin(ceta) ) ); 
    ceta(E<1e-2) = [];
    E(E<1e-2) = []; 
    power_dB = 10.*log10(E.^2); 
    power_dB = power_dB - max(power_dB);
    max(power_dB)
    polarplot(ceta,power_dB);
    rlim([-40 0]);
    

    Gives:

    enter image description here