Matlab 求自然频率,interp1 函数创建 NaN 值

Matlab finding natural frequency, interp1 function creates NaN values

我创建了以下代码,以找到使用冲击锤激发并附有加速度计的测试样本的自然频率。但是,我卡在了 interp_accelerance_dB_first。此插值创建一组 NaN 值,我不知道为什么。我觉得很奇怪,因为 interp_accelerance 工作正常。我希望有人能帮助我!

N = 125000;
fs = 1/(x(2)-x(1));
ts = 1/fs;
f = -fs/2:fs/(N-1):fs/2;

% Set x-axis of graph
x_max = (N-1)*ts;
x_axis=0:ts:x_max;

% find the first natural frequency between these boundaries 
First_lower_boundary = 15; 
First_upper_boundary = 30; 


Input = abs(fft(y)); %FFT input force
Output = abs(fft(o)); %FFT output acceleration

Accelerance = Output./Input;

bin_vals = [0 : N-1]; 
fax_Hz = bin_vals*fs/N; 
N_2 = ceil(N/2);

% Interpolate accelerance function in order to be able to average all accelerance functions 
Interp_accelerance = interp1(fax_Hz(1:N_2),Accelerance(1:N_2),x_axis); 


% --- Find damping ratio of first natural frequency 

% Determine the x-axis (from the boundries at the beginning of this script) 
x_axis_first_peak = First_lower_boundary:ts:First_upper_boundary;

% Accelerance function with a logarithmic scale [dB] 
Accelerance_dB_first =  20*log10(Accelerance(First_lower_boundary:First_upper_boundary));


% Interpolate the accelerance function [dB] 
Interp_accelerance_dB_first = interp1(fax_Hz(First_lower_boundary:First_upper_boundary),Accelerance_dB_first,x_axis_first_peak);

如果不知道 x,y,o 是什么,则很难确定,但通常 interp1 returns NaN 当您尝试在数据的 x 轴边界之外进行插值时。在代码末尾附加以下内容:

[min(fax_Hz(First_lower_boundary:First_upper_boundary)),max(fax_Hz(First_lower_boundary:First_upper_boundary))]
[min(x_axis_first_peak),max(x_axis_first_peak)]

如果第二段不在第一段内,那么您就找到了问题。

顺便说一下,我认为 interp_accelerance 可能容易出现同样的错误,同样取决于输入参数的确切性质。