How to solve dimension problem

I got script like this and for some reason it works with some audio samples and with other it doesnt.
asc
ascacsSamples have same length exactly same number of samples but for some reason it gives me this error.
%
rm
assignment because the size of the left side is 13-by-1 and the size of the right side
is 3-by-1.
Error in stFeatureExtractionmfcc (line 61)
mfccFeatures(:,i) = zeros(numOfFeatures, 1);
Error in Mfccshoww (line 39)
Curframe{i} = stFeatureExtractionmfcc(frame, fs, 0.09, 0.03);
[Signal, fs] = audioread('long_sample_1.wav');
if (size(Signal,2)>1)
Signal = (sum(Signal,2)/2);% convert to MONO
end
% win = 0.31;
% step = 0.2;
%Testsamplemfcc = stFeatureExtractionmfcc(Signal, fs, win, step);
%spectrum model
% % fs = 44100;
% % T = 1/fs;
% % L = length(Features);
% % f = fs*(0:L-1)/L;
% % t = (0:L-1)*T;
% %
win = 0.31;
%win = 0.310090703; %% length of a single bark match with the window and step
step = 0.1;
curPos = 1;
windowLength = (win * fs);
Stepf = round(step * fs);
d = cell(1,1);
Length_signal = length(Signal);
numberOfFrames = floor((Length_signal-windowLength)/Stepf) + 1;
% = Featuresaudio(1:windowLength);
% % Featuresaudio
% [Features] = getDFT(Featuresaudio, 44100);
Ham = window(@hamming, windowLength);
for i = 1:numberOfFrames
frame = (Signal(curPos:curPos+windowLength-1));
%frame = frame .* Ham;
Curframe{i} = stFeatureExtractionmfcc(frame, fs, 0.09, 0.03);
%Curframe{i} = mean(Curframe{i},2);
Curframe{i} = Curframe{i}; % in case of transposing
d{i}= ((Curframe{i}-mfccFeatures{1}).^2);
d{i} = sum(d{i});
d{i} = sum(d{i},2);
curPos = curPos + Stepf;
end
d = cell2mat(d);
idx = zeros(1,1)
if all(d(:) > 200)
fprintf('Dog wasnt found in any frame')
else
idx = find(d(:) < 170);
%fprintf('Dog detected in frame number %d\n',idx(:))
end
for i = 1:length(idx);
idx(i) = idx(i) *0.1;
end
idx = round(idx,2);
fprintf('Dog detected at second %0.2f\n',idx(:))

Answers (1)

Matt Gaidica
Matt Gaidica on 13 Dec 2020
It appears stFeatureExtractionmfcc() is returning multiple values. What is in that function?

6 Comments

function mfccFeatures = stFeatureExtractionmfcc(signal, fs, win, step)
% function Features = stFeatureExtraction(signal, fs, win, step)
%
% This function computes basic audio feature sequencies for an audio
% signal, on a short-term basis.
%
% ARGUMENTS:
% - signal: the audio signal
% - fs: the sampling frequency
% - win: short-term window size (in seconds)
% - step: short-term step (in seconds)
%
% RETURNS:
% - Features: a [MxN] matrix, where M is the number of features and N is
% the total number of short-term windows. Each line of the matrix
% corresponds to a seperate feature sequence
%
% (c) 2014 T. Giannakopoulos, A. Pikrakis
% if STEREO ...
if (size(signal,2)>1)
signal = (sum(signal,2)/2); % convert to MONO
end
% convert window length and step from seconds to samples:
windowLength = round(win * fs);
step = round(step * fs);
curPos = 1;
L = length(signal);
% compute the total number of frames:
numOfFrames = floor((L-windowLength)/step) + 1;
% number of features to be computed:
numOfFeatures = 3;
mfccFeatures = zeros(numOfFeatures, numOfFrames); %
Ham = window(@hamming, windowLength);
mfccParams = feature_mfccs_init(windowLength, fs);
for i=1:numOfFrames % for each frame
% get current frame:
frame = signal(curPos:curPos+windowLength-1);
frame = frame .* Ham;
frameFFT = getDFT(frame, fs);
if (sum(abs(frame))>eps)
% compute time-domain features:
%Features(1,i) = feature_zcr(frame);
%Features(2,i) = feature_energy(frame);
% Features(3,i) = feature_energy_entropy(frame, 10);
% compute freq-domain features:
if (i==1) frameFFTPrev = frameFFT; end;
% [Features(4,i) Features(5,i)] = ...
% feature_spectral_centroid(frameFFT, fs);
% Features(4,i) = feature_spectral_entropy(frameFFT, 10);
% Features(7,i) = feature_spectral_flux(frameFFT, frameFFTPrev);
% Features(8,i) = feature_spectral_rolloff(frameFFT, 0.90);
MFCCs = feature_mfccs(frameFFT, mfccParams);
mfccFeatures(1:13,i) = MFCCs;
% [HR, F0] = feature_harmonic(frame, fs);
% Features(22, i) = HR;
%Features(23, i) = F0;
%Features(23+1:23+12, i) = feature_chroma_vector(frame, fs);
else
mfccFeatures(:,i) = zeros(numOfFeatures, 1);
end
curPos = curPos + step;
frameFFTPrev = frameFFT;
end
mfccFeatures(13, :) = medfilt1(mfccFeatures(13, :), 3);
You would need to provide all the dependencies and your audio sample. This is a mess to debug for you otherwise.
mfccFeatures(1:13,i) = MFCCs;
That does make the array have at least 13 rows
mfccFeatures(:,i) = zeros(numOfFeatures, 1);
but that tries to assign to only 3 rows.
The difference is that the problem occurs when
if (sum(abs(frame))>eps)
is false. In other words, it happens when there is a frame that is effectively silent but which is not the first frame.
So it works as long as there is no silence in recording right ?
Can you provide me with solution ? please
No, the situation is undefined, the code can only extract features when features exist, and does not define what the output should be when no features exist.

Sign in to comment.

Tags

Asked:

on 13 Dec 2020

Commented:

on 26 Feb 2021

Community Treasure Hunt

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

Start Hunting!