Arrays have incompatible sizes for this operation.

3 views (last 30 days)
Hi everyone, I'm just getting started in audio signal processing and I have some trouble trying an example of the function splMeter.
Acording to the documentation I should be able to monitor sound pressure level for octave and fractional-octave bands but I get the mesagge
''Arrays have incompatible sizes for this operation.'' . Any idea how to fix this?
DOCUMENTATION SITE: https://la.mathworks.com/help/audio/ref/splmeter-system-object.html
%% Octave SPL Metering
% The |splMeter| enables you to monitor sound pressure level for octave and
% fractional-octave bands. In this example, you monitor the
% equivalent-continuous sound pressure level of 1/3-octave bands.
%%
% Create a |dsp.AudioFileReader| object to read in an audio file frame by
% frame. Create an |audioDeviceWriter| object so you can listen to the
% audio signal. Create an |splMeter| to measure
% the octave sound pressure level of the audio file. Use the default
% calibration factor of 1. Create a |dsp.ArrayPlot| object to visualize the
% equivalent-continuous SPL for each octave band.
source = dsp.AudioFileReader('/Users/noam/Desktop/whole.mp3');
fs = source.SampleRate;
player = audioDeviceWriter('SampleRate',fs);
SPL = splMeter( ...
'Bandwidth','1/3 octave', ...
'SampleRate',fs);
centerFrequencies = getCenterFrequencies(SPL);
scope = dsp.ArrayPlot(...
'XDataMode','Custom', ...
'CustomXData',centerFrequencies, ...
'XLabel','Octave Band Center Frequencies (Hz)', ...
'YLabel','Equivalent-Continuous Sound Level (dB)', ...
'YLimits',[20 90], ...
'ShowGrid',true, ...
'Name','Sound Pressure Level Meter');
%%
% In an audio stream loop:
%
% # Read in the audio signal frame.
% # Play the audio signal to your output device.
% # Call the SPL meter to return the equivalent-continuous sound pressure
% level in dB.
% # Display the sound levels using the scope. Update the scope only when
% the equivalent-continuous sound pressure level has changed.
%
% As a best practice, release your objects once complete.
%
LeqPrevious = zeros(size(centerFrequencies));
while ~isDone(source)
x = source();
player(x);
[~,Leq] = SPL(x);
for i = 1:size(Leq,1)
if LeqPrevious ~= Leq(i,:)
scope(Leq(i,:)')
LeqPrevious = Leq(i,:);
end
end
end
release(source)
release(player)
release(SPL)
release(scope)

Answers (1)

VBBV
VBBV on 1 Aug 2022
Edited: VBBV on 1 Aug 2022
LeqPrevious = zeros(1,30,2); % array preallocation is not the sme size of Leq
LeqPrevious = Leq(i,:,:); % inside the loop Leq is of size 1024x30x2
Array assignment inside the if - loop is not of same size. Change the size of preallocatied array to that of Leqprevious

Categories

Find more on Measurements and Spatial Audio in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!