使用fftoneside时出错 [英] error in using fftoneside

查看:115
本文介绍了使用fftoneside时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Hi I'm trying to calculate mfcc for which i'm windowing. I have seen this one post I'm getting error in fftOneSide.
my code is

    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'.

任何帮助表示赞赏 谢谢

any help is appreciated thanks

推荐答案

这是一篇非常古老的文章,如果仍然有人在乎,那将是一件很整洁的事情.我只是在下面最近的帖子中提供了我认为是答案的内容,我对此感到非常沮丧:

This is a really old post, it'd be neat if someone still cared. I just provided what I believe to be the answer in the recent post below, which I arrived at after a fair bit of frustration: Undefined function 'fftOneSide' for input arguments of type 'double'.

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

It should be noted here there's a call to a file, which I'm not sure if the author had originally or not. I suspect all the problems are related to a similarly named file in the sourcecode.

如果您看另一篇文章中的讨论,则在函数定义中将调用带有文件的方法demo-如果仅具有函数定义而不是原始文件,则该文件不存在.在注释掉第一行if nargin <1...demo例程后,调用[mag1, phase1, freq1]=fftOneSide(original, fs,1)在我的机器上可以正常工作,下面将显示代码.第三个参数等于1可以确保代码将运行打印例程,这一点很重要.

If you look at my discussion in the other post, within the function definition there is a call to a method demo with a file - which isn't present if you just have the function definition, not the original file. Calling [mag1, phase1, freq1]=fftOneSide(original, fs,1), after you comment out the first line if nargin <1... and the demo routine worked fine on my machine with the code which I'll show below. Having the third argument equal to 1 guarantees that the code will run the print routines, which is important.

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

In case the other thread is closed, I just want to show the output, when the input is manually defined, and I call [mag1, phase1, freq1]=fftOneSide(original, fs,1) on the properly edited method, with the inputs as in the original post shown below (notice the call is to original in fftOneSide..in the other post it was like this as well.. I believe the call was was meant to be instead for windowed, but I don't have the signals toolbox with hamming anyways):

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);

输出如下(下面的源代码!)

The output is as follows (source code below!)

无论如何,这是万一有人要使用此功能的源代码

Anyways, here's the source code in case anyone wants to use this function

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);

这篇关于使用fftoneside时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆