Show audio y-scale in dB, while mag is still linear

107 次查看(过去 30 天)
Can the waveform be plotted in MATLAB like how Adobe Audition does? See attached.
The waveform is still plotted with linear sample values (hence the positive and negative values), but the y-axis display is cleverly adjusted to reflect what the dB value of the magnitude would be at that point. I'm not sure if anything like this is possible in MATLAB. In audition, you can switch to linear samples for the Y-axis, and the waveform and scale would remain unchanged.

回答(1 个)

Pooja Kumari
Pooja Kumari 2023-9-15
编辑:Pooja Kumari 2023-9-20
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; % "audiorecorder" function is used to record audio data from an input device
recDuration = 5; %time duration is taken as 5 sec
recordblocking(sound_rec,recDuration);
% Get the recorded data
recData = getaudiodata(sound_rec); %getting the data from recorded sound
fs = myvoice.SampleRate; % Sample rate
%mag_dB = 20*log10(abs(recData));
mag_dB = mag2db(abs(recData)); % converting linear scale to dB scale
fs = myvoice.SampleRate; % Sample rate
% Plot the recorded waveform
t = (0:length(recData)-1)/fs;
figure;
subplot(2,1,1);
plot(t,recData); %plotting the linear scale of magnitude
xlabel('Time (s)');
ylabel('Amplitude(linear)');
title('Recorded Signal with y-scale(Linear)');
subplot(2,1,2);
plot(t, mag_dB); %plotting the dB scale of magnitude
xlabel('Time (s)');
ylabel('Amplitude(dB)');
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!

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by