Clear Filters
Clear Filters

How to convert an ADC code to voltage?

36 views (last 30 days)
Johannes Plate
Johannes Plate on 12 Dec 2022
Answered: Sai Pavan on 23 Jan 2024
Hello folks,
I made some measurements with a hydrophone( preamp30dB, frequency response 5Hz -125kHz, water reference value 10^-6 Pa) and a AD converter. I want to get the dB values and plot them via 1/3 Octaveanalysis. The AD values are 16 bits, working/bias voltage -5 - +5 V. The code runs properly..attached is the matlab data and the recorded data. I am asking for general check if the working routine is right and especially how to implement the hydrophone-preamp of 30 dB. Thanks in advance!
Kind regards
Johannes
% Steps:
% Vin(V) = OutputCode * LSBsize
% LSBsize(V/Code)= FSR/2^N
% FSR(V) = (m*Vref)/Gain
% m = 1;
%Counts -> Voltage -> pressure level(underwater)
FSR = 10; % -5V - 5V
bits = 65536; % 16 Bits
LSB = FSR/bits; % LSB Size is the value or weight of the least significant bit (LSB) in the ADC code.
% Compute AD voltage
Vin = data_specific_cut * LSB; % [Volts]
% Compute pressure level (-163 dB Sensitivity at 1kHz from datasheet)
% [-163 dB re 1V/uPa -> 43dB re 1V/Pa -> 10^(-43/20)-> 0.007079457843841 V/Pa ]
Sensitivity = 0.007079457843841; % Transferfactor
Pressure = Vin/Sensitivity; % RMS for Vin??
Pref = 1*10e-6; % [reference value for water = 1 muPa = 10^-6 Pa]
dB = 20*log10(Pressure/Pref); % [dB re 1V/uPa]
% 30 dB Preamp hydrophone
data_dB = abs(dB); % doublecomplex to normal double
the Second part is the 1/3 Octaveanalysis
fs = 250000;
[P,f] = poctave(data_dB,fs,'FrequencyLimits',[10 round(fs/2.2)],'FilterOrder',6,'BandsPerOctave',3), 'Weighting','Z';
ref =-20*log10(10e-6); % reference value under water 10^-6 Pa
figure('Name','1/3 Octaveanalysis');
hold on
title('Measurement');
plot(f,10*log(P)+ref);
grid on
%grid minor
xlabel('Mid-band frequency / Hz');
ylabel('Pegel 1/3-Oktave / dB re 1\muPa)');
xlim([10 16000])
set(gca,'Xscale','log');
set(gca,'XMinorTick', 'off', 'XMinorGrid', 'off');
xticks([16 32 63 125 250 500 1000 2000 4000 8000 16000]);
hold on
xticklabels({'16','32','63','125','250','500','1k','2k','4k','8k','16k'});
  2 Comments
Image Analyst
Image Analyst on 12 Dec 2022
Not sure I understand. Do you need to take the value from MATLAB and send it to an A-to-D converter - a piece of hardware that will take your digital signal from MATLAB and create an actual voltage like you can measure with an oscilloscope or voltmeter?
Johannes Plate
Johannes Plate on 12 Dec 2022
There is the hydrophone taking the measurement of pressure converting to voltage. Then there is the AD converter scanning the voltage and transferring it into AD counts. I want to compute this counts into unweighted dB Values and plot it in a 1/3 octaveanalysis. I hope this information helps.

Sign in to comment.

Answers (1)

Sai Pavan
Sai Pavan on 23 Jan 2024
Hello Johannes,
I understand that you want to confirm the corectness of the working procedure of converting ADC code to voltage.
Your procedure for converting ADC codes to voltage and then to pressure levels in dB re 1 µPa seems generally correct. However, there are a few points that need to be addressed.
  • ADC Code to Voltage Conversion: The ADC conversion formula you have is correct. However, the number of bits should be used as `2^N` where `N` is the number of bits (16 in your case).
FSR = 10; % Full Scale Range is 10V (-5V to +5V)
N = 16; % Number of bits
LSB = FSR / (2^N); % LSB Size in V/code
Vin = data_specific_cut * LSB; % Convert ADC code to voltage in Volts
  • Including the Preamp Gain: The preamp provides a 30 dB gain which needs to be included in your calculations. A gain of 30 dB corresponds to a factor of `10^(30/20)`. And then, you need to divide the pressure by this factor because the measured voltage is already amplified by the preamp.
PreampGainFactor = 10^(30/20); % Preamp gain converted to linear scale
Pressure = Vin / (Sensitivity * PreampGainFactor); % Pressure in Pascals
  • 1/3 Octave Analysis: For the 1/3 octave analysis, one should be careful with the units. The `poctave` function typically expects raw pressure data, not data in dB. You should not apply the `20*log10()` before passing the data to `poctave`. Also, you should use the pressure data directly, not the absolute value of dB.
fs = 250000;
% The octave analysis should be done on Pressure, not dB
% since Filters in 1/3 octave analysis are not applied to pressure's logarithmic representation (dB)
[P, f] = poctave(Pressure, fs, 'FrequencyLimits', [10 round(fs/2.2)], 'FilterOrder', 6, 'BandsPerOctave', 3);
% Plot the octave levels in dB re 1µPa
ref = -20 * log10(10e-6); % Reference value under water 10^-6 Pa
figure('Name', '1/3 Octave Analysis');
hold on;
title('Measurement');
plot(f, 10 * log10(P) + ref);
grid on;
xlabel('Mid-band frequency / Hz');
ylabel('Level 1/3-Octave / dB re 1\muPa');
xlim([10 16000]);
set(gca, 'Xscale', 'log');
xticks([16 32 63 125 250 500 1000 2000 4000 8000 16000]);
xticklabels({'16', '32', '63', '125', '250', '500', '1k', '2k', '4k', '8k', '16k'});
hold off;
Make sure to validate the sensitivity conversion and include the preamp gain correctly in your calculations. If you have the raw ADC data and the hydrophone sensitivity in dB re 1V/µPa, you can directly apply these changes to your existing code.
Hope it helps!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!