Decibels Engineers often measure the ratio of two power meas
Decibels Engineers often measure the ratio of two power measurements in decibels, or dB. The equation for the ratio of two power measurements in decibels is: dB = 10log_10 P_2/P_1 where P_2 is the power level being measured, and P_1 is some reference power level. Engineers have a special unit for dB power levels with respect to a 1 mW reference: dBm. If we use a reference power level P_1 of 1 times 10^-3 watts (1 mW) and we require that P_2 is also in watts, then the equation above becomes: dBm = 10 log_10 P2/1 times 10^-3 Write a MATLAB script that creates a plot of the power P_2 in watts versus the power in dBm (i.e. P_2 should be plotted on the y-axis and dBm on the x-axis.) The vector that contains your P_2 values should range from 1 to 100 watts in increments of 2 watts (e.g. p2 (1:2:100]). Create both a linear xy plot (using plot) and a linear-log xy plot (using semi logy). Be sure to include a proper title, axis labels, a legend and axis grid lines in your plots. Use good programming practices in your program.
Solution
P1 = 0.001; % Step one refernece power 0.001 W i.e. 1 x 10-3 W or 1 mW
P2 = 1 : 2 : 100; % P2 values ranging from i to 100 W in increments of two.
dB = 10 * log10(P2 / P1); % calculating dB equivalent
%For Linear xy plot
plot(P2, dB)
title(\'linear plot\'); xlabel(\'P_2\'); ylabel(\'dB\'); legend(\'10log(P_2 / P_1)\'); % title and labels
grid on
%For Linear-log xy plot
semilogy(P2, dB)
title(\'Simple Plot\'); xlabel(\'P_2\'); ylabel(\'dB\'); legend(\'10log(P_2 / P_1)\');
grid on
