0

嗨,我正在尝试计算我正在为其开窗的 mfcc。我看过这篇文章,我在 fftOneSide 中遇到错误。
我的代码是

    waveFile='test_preEmphasis.wav';
    [y, fs]=wavread(waveFile);

    n=512;
    t=(1:n)'/fs;
    startIndex=30418;
    endIndex=startIndex+n-1;

    original=y(startIndex:endIndex);
    windowed=original.*hamming(n);
    [mag1, phase1, freq1]=fftOneSide(original, fs);
    [mag2, phase2, freq2]=fftOneSide(windowed, fs);

    subplot(3,2,1); plot(original); grid on; axis([-inf inf -1 1]); 
    title('Original signal');
    subplot(3,2,2); plot(windowed); grid on; axis([-inf inf -1 1]);  
    title('Windowedsignal');
    subplot(3,2,3); plot(freq1, mag1); grid on; 
    title('Energy spectrum (linear scale)');
    subplot(3,2,4); plot(freq2, mag2); grid on; 
    title('Energy spectrum (linear scale)');
    subplot(3,2,5); plot(freq1, 20*log(mag1)); grid on; 
    axis([-inf inf -80 120]); title('Energy spectrum (db)');
    subplot(3,2,6); plot(freq2, 20*log(mag2)); grid on; axis([-inf inf -80 120]);  
    title('Energy spectrum (db)');

我得到的错误是

    ??? Undefined function or method 'fftOneSide' for input arguments of type 'double'.

任何帮助表示感谢

4

1 回答 1

2

这是一个非常古老的帖子,如果有人仍然关心它会很整洁。我刚刚在下面最近的帖子中提供了我认为的答案,这是我在经历了一些挫折之后得出的:Undefined function 'fftOneSide' for input arguments of type 'double'

应该注意这里有一个文件调用,我不确定作者是否最初有。我怀疑所有问题都与源代码中一个类似命名的文件有关。

如果您查看我在另一篇文章中的讨论,则在函数定义中会调用demo带有文件的方法-如果您只有函数定义而不是原始文件,则该方法不存在。调用[mag1, phase1, freq1]=fftOneSide(original, fs,1),在您注释掉第一行之后if nargin <1...,该demo例程在我的机器上运行良好,代码如下所示。第三个参数等于 1 保证代码将运行打印例程,这很重要。

如果另一个线程被关闭,我只想显示输出,当手动定义输入时,我调用[mag1, phase1, freq1]=fftOneSide(original, fs,1)正确编辑的方法,输入如下所示的原始帖子(注意调用是originalin fftOneSide. .在另一篇文章中也是这样..我相信这个电话本来是为了代替windowed,但无论如何我都没有信号工具箱hamming):

fs=8000;
t=(1:512)'/fs; %'// <-- prevents string markdown
f=306.396;
original=sin(2*pi*f*t)+0.2*randn(length(t),1);
% windowed=original.*hamming(length(t)); % defined in other post
[mag1,phase1,freq1]=fftOneSide(original,fs); % I call fftOneSide(original,fs,1);

输出如下(源码如下!)

fftOneSide 的输出

无论如何,这是源代码,以防有人想使用此功能

function [magSpec, phaseSpec, freq, powerSpecInDb]=fftOneSide(signal, fs, plotOpt) 
% fftOneSide: One-sided FFT for real signals 
%   Usage: [magSpec, phaseSpec, freq, powerSpecInDb]=fftOneSide(signal, fs) 
% 
%   For example: 
%       [y, fs]=wavread('welcome.wav'); 
%       frameSize=512; 
%       startIndex=2047; 
%       signal=y(startIndex:startIndex+frameSize+1); 
%       signal=signal.*hamming(length(signal)); 
%       plotOpt=1; 
%       [magSpec, phaseSpec, freq, powerSpecInDb]=fftOneSide(signal, fs, plotOpt); 

%   Roger Jang, 20060411, 20070506 

if nargin<1, selfdemo; return; end %=== (MathBio: Comment this out!)
if nargin<2, fs=1; end 
if nargin<3, plotOpt=0; end 

N = length(signal);         % Signal length 
freqStep = fs/N;            % Frequency resolution 
time = (0:N-1)/fs;          % Time vector 
z = fft(signal);            % Spectrum 
freq = freqStep*(0:N/2);        % Frequency vector 
z = z(1:length(freq));          % One side 
z(2:end-1)=2*z(2:end-1);        % Assuming N is even, symmetric data is multiplied by 2
magSpec=abs(z);             % Magnitude spectrum 
phaseSpec=unwrap(angle(z));     % Phase spectrum 
powerSpecInDb=20*log(magSpec+realmin);  % Power in db 

if plotOpt 
    % ====== Plot time-domain signals 
    subplot(3,1,1); 
    plot(time, signal, '.-'); 
    title(sprintf('Input signals (fs=%d)', fs)); 
    xlabel('Time (seconds)'); ylabel('Amplitude'); axis tight 
    % ====== Plot spectral power 
    subplot(3,1,2); 
    plot(freq, powerSpecInDb, '.-'); grid on 
    title('Power spectrum'); 
    xlabel('Frequency (Hz)'); ylabel('Power (db)'); axis tight 
    % ====== Plot phase 
    subplot(3,1,3); 
    plot(freq, phaseSpec, '.-'); grid on 
    title('Phase'); 
    xlabel('Frequency (Hz)'); ylabel('Phase (Radian)'); axis tight 
    end 

% ====== Self demo (MathBio: Comment all of this out! )
function selfdemo 
[y, fs]=wavread('welcome.wav'); 
frameSize=512; 
startIndex=2047; 
signal=y(startIndex:startIndex+frameSize+1); 
signal=signal.*hamming(length(signal)); 
[magSpec, phaseSpec, freq, powerSpecInDb]=feval(mfilename, signal, fs, 1);
于 2016-02-11T17:46:21.963 回答