Arrays have incompatible sizes for this operation.

조회 수: 3 (최근 30일)
Luis Angel Manriquez Ramirez
Luis Angel Manriquez Ramirez 2022년 8월 1일
편집: VBBV 2022년 8월 1일
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)

답변 (1개)

VBBV
VBBV 2022년 8월 1일
편집: VBBV 2022년 8월 1일
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

카테고리

Help CenterFile Exchange에서 Measurements and Spatial Audio에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by