Filter löschen
Filter löschen

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

26 Ansichten (letzte 30 Tage)
street_car
street_car am 4 Aug. 2022
Bearbeitet: Pooja Kumari am 20 Sep. 2023
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.

Antworten (1)

Pooja Kumari
Pooja Kumari am 15 Sep. 2023
Bearbeitet: Pooja Kumari am 20 Sep. 2023
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!

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by