📄 find_f.m
字号:
function [f]=find_f(x,varargin)% FIND_F Find fundamental frequency and harmonics%% F=FIND_F(X)%% Find fundamental frequency and harmonics.% $Id: find_f.m 106 2006-02-13 12:32:11Z mairas $f0 = -1;if nargin > 2 if strcmp(varargin{1},'F0') f0 = varargin{2}; endendlx = len(x);fftsize = 2^(floor(log(lx)/log(2))+1);% get frequency response X=fft(x,fftsize);Xabs=abs(X);% get f0if f0 == -1 f0 = find_f0(x);end% check F0if f0 == 0 % no F0 found - return with null f = []; returnend% get N (vector of harmonics to get)N = 1:floor((x.time.fs/2)/f0);% find local peaksf_N=N; % initialise to the final sizefor i=N f_N(i) = localmax(Xabs,f0,i);endf=[f_N x.time.fs-fliplr(f_N)];%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function f=localmax(Xabs,f0,N)% LOCALMAX Find a largest spectral peak around N*f0% F=LOCALMAX(XABS,FX,F0,N) returns the frequency, at which XABS% gains its largest value. XABS is the absolute magnitude% spectrum, FX are the corresponding frequency points, F0 is the% assumed fundamental frequency and N is the order of harmonics.fmin=(N-0.5)*f0;fmax=(N+0.5)*f0;Imin=at(Xabs,fmin);Imax=at(Xabs,fmax);[foo,I]=max(Xabs(Imin:Imax));f = Xabs.frequency.f(Imin-1+I);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -