Hello,
I understand that you are facing issues with waveform having linear sample values with positive and negative values of magnitude, but you want to display y-axis to auto adjust to reflect magnitude of waveform in dB(decibels). MATLAB does not have built-in functionality to automatically adjust the y-axis display of the waveform to reflect the dB value of the magnitude at each point.
However, here are the following alternatives for displaying the waveform in decibel scale in MATLAB:
- You can use “subplot” function to plot the waveform in linear scale on one plot and the same waveform converted to decibel scale on another plot. Here is a code for your reference:
sound_rec = audiorecorder;
recordblocking(sound_rec,recDuration);
recData = getaudiodata(sound_rec);
mag_dB = mag2db(abs(recData));
t = (0:length(recData)-1)/fs;
ylabel('Amplitude(linear)');
title('Recorded Signal with y-scale(Linear)');
title('Recorded Signal with y-scale(dB)');
ylim([min(mag_dB), max(mag_dB)]);
In this example, we use “subplot” function to create two subplots vertically. Recorded data from linear scale in first subplot is converted to decibel scale using “mag2db” function.
mag_dB_func = mag2db(abs(recData));
You can refer to the below documentation to learn more about “mag2db” function:
I hope this helps!