【问题标题】:Error using wavread Invalid Wave File. Reason: Cannot open file使用 wavread 时出错 无效的波形文件。原因:无法打开文件
【发布时间】:2013-03-26 00:27:08
【问题描述】:

我在使用 wavread 时遇到错误(第 67 行) 波形文件无效。原因:无法打开文件。

energy_per_frame 中的错误(第 2 行)[inpu fs] = wavread(file);

这是调用 energy_per_frame 的函数的源代码。

 [inpu fs] = wavread(file);
clc;clear;close all;
file = input('Enter name of wav file  ', 's');
counter=0;
for test_number = 0:4
for test_number2 = 0:20
        counter=counter+1;
        reference = dtw_avg(test_number2);
        test = energy_per_frame(file);
        distance(counter) = dtw(test,reference);
end

这是函数energy_per_frame的源代码

 [inpu fs] = wavread(file);
    fn = fs/2;
bins = 512; %useable bins
frame_length = bins;
window = hamming(frame_length);
overlap = .5;
number_of_frames = (length(inpu)/(frame_length)/overlap) - 1;

这里有什么问题?

【问题讨论】:

    标签: matlab


    【解决方案1】:

    嗯,你的函数定义应该是这样的

    function [ output_args ] = energy_per_frame( input_args )
    %UNTITLED Summary of this function goes here
    %   Detailed explanation goes here
    
    
    end
    

    您似乎缺少 function 关键字。

    但是,如果第一个块只是应该是一个脚本,那么您在实际获得用户输入文件名之前就调用了 wavread。此外,实际上没有必要像在函数中那样调用 clear 等。

    【讨论】:

    • 我认为test_Number2=0:20有问题,如果我改成1:4就没有这个错误了。但我希望它采样更多。
    • 这是您的代码的另一个问题,我没有注意到。在 Matlab 中没有 0 索引。第一个元素的索引始终为 1。当 x 是矩阵时,任何像 x(0) 这样的表达式都会出错。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-11
    • 2020-07-11
    • 2012-12-24
    • 1970-01-01
    • 2020-05-21
    相关资源
    最近更新 更多