我在Matlab中制作一个脚本,以便从音频信号中提取特征。这是代码:
clear;clc;
folder = dir('sonidos');
m = length(folder);
fileW = fopen('caracteristicas.txt','wt');
for i = 3:m
file = strcat('sonidos/', folder(i).name);
fprintf('Leyendo Archivo: %s \n', file);
[y, Fs] = audioread(file);
max = max(y);
mean = mean(y);
min = min(y);
median = median(y);
peak2peak = peak2peak(y);
peak2rms = peak2rms(y);
rms = rms(y);
rssq = rssq(y);
std = std(y);
var = var(y);
kurtosis = kurtosis(y);
power = (norm(y)^2)/length(y);
fprintf('Caracteristicas: %f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f \n', ...
Fs, max, mean, min, median, peak2peak, peak2rms, rms, rssq, std, var, kurtosis, power);
fprintf(fileW,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f \n', ...
Fs, max, mean, min, median, peak2peak, peak2rms, rms, rssq, std, var, kurtosis, power);
end
fclose(fileW);
音频文件位于'sonidos'文件夹中。当我执行代码时MatLab说:
Leyendo Archivo: sonidos/1.wav
Caracteristicas: 22050.000000,0.352722,-0.000128,-0.435028,-0.000092,0.787750,17.550266,0.024788,6.027810,0.024787,0.000614,47.710490,0.000614
Leyendo Archivo: sonidos/2.wav
Subscript indices must either be real positive integers or logicals.
感谢您的帮助!
答案 0 :(得分:1)
您的局部变量会覆盖Matlab函数。
例如:min = min(y);
,创建一个名为min
的局部变量,从现在开始,当您使用min
时,将使用该变量而不是min
功能
检查以下内容:
clear;clc;
folder = dir('sonidos');
m = length(folder);
fileW = fopen('caracteristicas.txt','wt');
for i = 3:m
file = strcat('sonidos/', folder(i).name);
fprintf('Leyendo Archivo: %s \n', file);
[y, Fs] = audioread(file);
max0 = max(y);
mean0 = mean(y);
min0 = min(y);
median0 = median(y);
peak2peak0 = peak2peak(y);
peak2rms0 = peak2rms(y);
rms0 = rms(y);
rssq0 = rssq(y);
std0 = std(y);
var0 = var(y);
kurtosis0 = kurtosis(y);
power0 = (norm(y)^2)/length(y);
fprintf('Caracteristicas: %f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f \n', ...
Fs, max0, mean0, min0, median0, peak2peak0, peak2rms0, rms0, rssq0, std0, var0, kurtosis0, power0);
fprintf(fileW,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f \n', ...
Fs, max0, mean0, min0, median0, peak2peak0, peak2rms0, rms0, rssq0, std0, var0, kurtosis0, power0);
end
fclose(fileW);
我修改了你的局部变量名称(只是将0
添加到每个名称的末尾)。