Matlab找到固有频率,interp1函数创建NaN值

时间:2016-03-29 22:06:04

标签: matlab interpolation frequency nan frequency-analysis

我创建了以下代码,以便找到测试样品的固有频率,该样品通过使用冲击锤激发并且连接有加速度计。但是,我被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);

1 个答案:

答案 0 :(得分:0)

在不知道x,y,o是什么的情况下很难确定,但是当您尝试在数据的x轴范围之外进行插值时,interp1通常会返回NaN。在代码末尾添加以下内容:

[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可能容易受到同样的错误,同样取决于输入参数'确切的性质。