我创建了下面的代码,以寻找一个测试样本的固有频率,它是由一个冲击锤激发,并有一个加速度计连接在它上。然而,我被困在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);发布于 2016-03-29 23:55:37
在不知道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可能会受到同样的错误的影响,这同样取决于输入参数的确切性质。
https://stackoverflow.com/questions/36295973
复制相似问题