类型为"double"的输入参数的未定义函数"fftOneSide" [英] Undefined function 'fftOneSide' for input arguments of type 'double'
问题描述
我正在使用MATLAB R2013.
I am using MATLAB R2013.
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));
[mag1,phase1,freq1]=fftOneSide(original,fs);
错误:
类型为'double'的输入参数的未定义函数'fftOneSide'
Undefined function 'fftOneSide' for input arguments of type 'double'
推荐答案
此问题是在上一个SO问题中提出的,到目前为止,显然没有任何答复: 使用fftoneside的错误
This question was raised in a previous SO question, with apparently no response until now: error in using fftoneside
在定义下面的功能后,在不使用汉明功能的情况下使用信号输入(我的计算机上没有信号工具箱)(我在底部和第一行注释了演示代码, if nargin <1
obv !!),我在Matlab2015a上运行了它.一切正常!设置plotOpt=1
(使用三个参数进行调用,最终等于1)可提供证明:
Using your input for the signal, without using the hamming function (I don't have the signal toolbox on my computer), after defining the function below (I commented out the demo code at the bottom part and the first line with if nargin <1
obv!!), I ran it on Matlab2015a. It ran fine! Setting plotOpt=1
(that is calling with three arguments, the final equal to 1) provides proof:
我唯一能想到的是,在源代码中它要求一个文件作为输入-我假设您没有.如果您注释掉nargin <1
部分,最后注释掉整个selfdemo,请查看这是否无法按您的意愿进行.如果没有,我就完全困惑了!
The only thing I can think of, is that in the sourcecode it asks for a file as input - which I'm assuming you don't have. If you comment out the nargin <1
part, and the whole selfdemo at the end, see if this doesn't work as you want it to. If it doesn't, I'm completely baffled!
我已经看过了该函数的源代码(如下),它也显示了正确的用法.如您所见,它们正在从文件中读取信号和fs
值,而不是像您在此处那样定义它们.我们看不到他们选择了什么值,这有点痛苦.
I've taken a look at the source code (below) for this function, which also shows proper usage. As you can see they're reading the signal and fs
values in from a file, rather than defining them as you have here. It's a bit of a pain we can't see what values they chose.
请注意,该呼叫要求指定plotOpt
,但如果您未指定,则开始时的nargin
呼叫应为您将其设置为0(对吗?).我不认为自2012年以来默认函数声明就没有发生过变化-但是如果有的话,使用三个参数调用该函数就可以解决这一问题.注意:如果不设置plotOpt = 1,绘图将不会继续.
Notice the call asks for plotOpt
to be specified, though if you don't specify it, the nargin
calls at the beginning should set it to 0 for you (right?). I don't think default function declarations have changed since 2012 - but if they have, calling the function with three arguments will take care of that. Note: if don't set plotOpt=1, the plots won't proceed.
http://read.pudn.com /downloads99/sourcecode/others/404673/audioProcessing/fftOneSide.m__.htm
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 % MBio: comment 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 MBio: comment ALL this code 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);
这篇关于类型为"double"的输入参数的未定义函数"fftOneSide"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!