![]() |
MATLAB中音频所需的帮助
我正在尝试编写一个.m文件以从音轨中提取能量特征,但是我似乎在实现它时遇到了麻烦:
% Formula for calculating RMS [f, fs, nb] = wavread('Three.wav'); frameWidth=441; %10ms numSamples=length(x); numFrames=(numSamples/1); energy(frame)=0; for frame=1:numFrames, startSample=(frame-1)*frameWidth+1; endSample=startSample+frameWidth-1; % Calculate frame energy for i=startSample:endSample energy(frame)=energy(frame)+x(i)^2; end end 我在MATLAB中运行该文件并得到以下错误: [INDENT] ???尝试访问x(2);索引超出范围,因为numel(x)= 1。 ==> myrms在12能量(帧)=能量(帧)+ x(i)^ 2时的错误; [/INDENT]任何帮助将非常感激。 [B]回答:[/B] 您应该使用f而不是x ,因为f是从.wav文件加载的实际信号。变量x可能只是工作空间中的其他标量,这就是为什么看到错误的原因。 还应该对您的代码进行其他一些更正/改进。首先,正如[URL="https://stackoverflow.com/questions/3406361/help-required-with-audio-in-matlab/3406399#3406399"]Paul R指出的那样[/URL] ,您需要更正计算numFrames 。其次,应将energy初始化为零的向量。第三,您可以将内部for循环简化为单行矢量化操作。 这是我重写代码的方式( [I]编辑:基于注释,我更新了代码以保存在循环中计算出的一些额外变量[/I] ): [y, fs, nb] = wavread('Three.wav'); %# Load the signal into variable y frameWidth = 441; %# 10 msec numSamples = length(y); %# Number of samples in y numFrames = floor(numSamples/frameWidth); %# Number of full frames in y energy = zeros(1,numFrames); %# Initialize energy startSample = zeros(1,numFrames); %# Initialize start indices of frame endSample = zeros(1,numFrames); %# Initialize end indices of frame for frame = 1:numFrames %# Loop over frames startSample(frame) = (frame-1)*frameWidth+1; %# Starting index of frame endSample(frame) = frame*frameWidth; %# Ending index of frame frameIndex = startSample(frame):endSample(frame); %# Indices of frame samples energy(frame) = sum(y(frameIndex).^2); %# Calculate frame energy end [url=https://stackoverflow.com/questions/3406361]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 03:04。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.