# Could you help me in converting y axis in dB units ? I could not get my axis in dB units after doing FFT

Here is all codes, I could not find how and where to add ‘20*log(Vout/Vin)’ equation to convert voltage values to dB units. If there are other ways to do that I would like to listen and know.

clc;clear all;close all;

D = Data1(:,1); %Voltage value
T = Data1(:,2); % Time data
Ts = 0.004; % Sampling Interval (s)
Fs = 1/Ts; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency
LF = size(D,1); % Length of Data Vector
figure(1) % Plot Data
plot(T, D)
xlabel(‘Time(µs)’);
ylabel(‘Voltage(V)’);
grid

FF = fft(D)/LF; % Fourier Series of Data, Freq Vector
Fv = linspace(0,1,fix(LF/2)+1)*Fn;
Iv = 1:length(Fv); % Index Vector
figure(2); % Plot FFT
plot(Fv, abs(FF(Iv)))
grid
xlabel(‘Frequency (Hz)’)
ylabel(‘Power(dB)’)
axis([0 130 ylim]);

Assuming that `abs(fft(lv)) = vout` and `vin=1`, then you want to compute `20 * log10( abs(fft( lv ))/1 )`.

If you have control package installed, you can do :

``````pkg load control
dbvalue = mag2db( abs(fft( lv )) );
``````

Hi Octavecontrib,

Thank you for the answer these ones worked for me well.