首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >interp1函数求取固有频率时,生成NaN值。

interp1函数求取固有频率时,生成NaN值。
EN

Stack Overflow用户
提问于 2016-03-29 22:06:03
回答 1查看 369关注 0票数 1

我创建了下面的代码,以寻找一个测试样本的固有频率,它是由一个冲击锤激发,并有一个加速度计连接在它上。然而,我被困在interp_accelerance_dB_first。这个插值创建了一组NaN值,我不知道为什么。我觉得很奇怪,因为interp_accelerance工作得很好。我希望有人能帮我!

代码语言:javascript
复制
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);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-29 23:55:37

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

代码语言:javascript
复制
[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可能会受到同样的错误的影响,这同样取决于输入参数的确切性质。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36295973

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档