0
$\begingroup$

I exported a diagram from FDTD simulation, and now I want to change the magnitude to dB, here is the exported codes:

ax1 = axes; 

plot(lum.x0,lum.y0)

set(ax1, 'XLim', [1.49806e-06 1.60194e-06])

set(ax1, 'YLim', [-0.0232806 1.22328])

set(ax1,'XGrid', 'on')

set(ax1,'YGrid', 'on')

and the ploted spectrum is shown below enter image description here

I just wondering how to convert the magnitude to dB? I know there is a function called mag2dB, but i just dont know how to use it. any help would be very appreciate.

$\endgroup$
1
  • $\begingroup$ try semilogy(lum.x0,lum.y0) FYI, there is also semilogx() $\endgroup$ – AlexTP Sep 1 '20 at 17:40
1
$\begingroup$
valueInDB = 10*log10(magnitude.*conj(magnitude));
$\endgroup$
0
1
$\begingroup$

Direct conversion from magnitude to dB is done by $20\text{log}_{10}\big(|x|\big)$.

I will highlight the parallel to Hilmar's answer by saying that the conversion from power to dB is done by $10\text{log}_{10}\big(|x|^2\big)$, so by following Hilmar you do $10\text{log}_{10}\big(xx^*\big)=10\text{log}_{10}\big(|x|^2 \big)$ which can be simplified to $20\text{log}_{10}\big(|x| \big)$.

MATLAB has a function mag2db which accomplishes this conversion, or you can simply do 20*log10(abs(lum.y0)).

ax1 = axes; 

plot(lum.x0, mag2db(lum.y0))

set(ax1, 'XLim', [1.49806e-06 1.60194e-06])

set(ax1, 'YLim', [-0.0232806 1.22328])

set(ax1,'XGrid', 'on')

set(ax1,'YGrid', 'on')
$\endgroup$
1
  • $\begingroup$ thank you so much for your help! $\endgroup$ – Dong junkai Sep 2 '20 at 2:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.