首页 > 解决方案 > 为什么 MATLAB 中两个数组的卷积会产生“NaN”值?

问题描述

我正在尝试计算曲线与缩放小波的卷积。使用 MATLAB 卷积函数https://www.mathworks.com/help/matlab/ref/conv.html,结果开头有大量的 'NaN' 值,我想了解这些在哪里来自(哪里。

我对卷积的直觉是不应该这样,因为我在卷积的每个点都定义了上限。我想象这个卷积的方式是小波被翻转,然后在曲线上从左到右移动。当它移动时,小波与曲线交点下方的区域存储在输出中。如果是这种情况,则结果输出应该存在并且在卷积的所有点上都是正的,除非没有重叠并且结果为 0。

% The curve is a set of responses to presented stimuli,
% and the following is an example:

curve = [0.0500, 0.1000, 0.1500, 0.2000, 0.3000, 0.5000, 0.8000;
 11.6465, 14.8354, 5.0695, 0.4856, 0.5858, 0.2863, 0.3864];

% The scaled Mexican hat wavelet is as follows:

acuteness = 1000;
[mexh_y, mexh_x] = mexihat(-5,5,acuteness);
max_response = max(curve(2,:));
wav_x = mexh_x/100;
wav_y = mexh_y * (max_response+1);

% Here wav_x are the wavelet’s x-values and wav_y are the wavelet’s y-values.

% I interpolate the original curve to have more values as follows:

max_presentation = max(curve(1,:));
step = max_presentation/acuteness;
sf_vals_for_interpolation = [step:step:max_presentation];
interp_curve = interp1(curve(1,:),curve(2,:),sf_vals_for_interpolation);

% Now I’d like to perform a convolution:

conv_res = conv(interp_curve, wav_y);

如摘要中所述,生成的卷积包含许多我想理解的“NaN”值。

标签: matlabnanconvolutionwavelet

解决方案


推荐阅读