why is function giving me an empty matrix ?

1 回表示 (過去 30 日間)
Kamil Kacer
Kamil Kacer 2020 年 11 月 17 日
コメント済み: Walter Roberson 2020 年 11 月 17 日
>> stFeatures = stFeatureExtraction('signal', 44100, 0.2, 0.1)
stFeatures =
35×0 empty double matrix
function Features = stFeatureExtraction(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)
signal = 'audio.wav';
% 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 = 35;
Features = 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(6,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);
Features(9:21,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
Features(:,i) = zeros(numOfFeatures, 1);
end
curPos = curPos + step;
frameFFTPrev = frameFFT;
end
Features(35, :) = medfilt1(Features(35, :), 3);

採用された回答

Walter Roberson
Walter Roberson 2020 年 11 月 17 日
stFeatures = stFeatureExtraction('signal', 44100, 0.2, 0.1)
Do not pass in the character vector 'signal' there: pass in the variable that holds the signal with no '' around it
  3 件のコメント
Kamil Kacer
Kamil Kacer 2020 年 11 月 17 日
got it
Walter Roberson
Walter Roberson 2020 年 11 月 17 日
[signal, Fs] = audioread('audio.wav');
stFeatures = stFeatureExtraction(signal, Fs, 1, 2);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by