如何在 MATLAB 中进行 Python 插值?
how to do this Python interpolation in MATLAB?
我需要在 MATLAB 中转换这段 Python 代码,但我似乎不知道该怎么做。
python loop
T = 1968,
F = 1025,
used_freq = 22050,
freqs = 1621 x 1 vector,
log_scale_spec = 1968 x 1025 matrix,
cent_spec was initialized with zeros = 1968 x 1621 matrix,
and the "linspace(0, used_freq, F)" operation gives a 1025 x 1 vector
插值似乎是三次插值 (k = 3)。
我只是不知道如何在 MATLAB 中将所有这些构造成一个 for 循环。
到目前为止,我尝试过这样的事情:
matlab loop
f代表操作“linspace(0, used_freq, F)'”
注意在 Matlab 中,它必须用 ' .
转置
我试图让它在 Matlab 中工作,我不确定该怎么做,可能是在循环中缺少一些索引,或者可能需要转置某些 vectors/matrices 或组合那些。
T = 1968,
F = 1025,
used_freq = 22050,
下面这行是错误的说法。 freqs 的高维必须小于 F。我可以补充一点 freqs 必须包含索引,而不是频率。
freqs = 1621 x 1 vector - wrong
freqs = F< x 1 vector - right
log_scale_spec = T x F matrix,
您可以删除下面的行,因为 _cent_spec_ 在循环外求值
cent_spec=zeros(T,F<)
f=linspace(0, used_freq, F);
for t=1:T
Sp(:,t)=interp1(f,log_scale_spec(:,t),'cubic');
end
cent_spec=Sp(:,freqs);
我需要在 MATLAB 中转换这段 Python 代码,但我似乎不知道该怎么做。
python loop
T = 1968,
F = 1025,
used_freq = 22050,
freqs = 1621 x 1 vector,
log_scale_spec = 1968 x 1025 matrix,
cent_spec was initialized with zeros = 1968 x 1621 matrix,
and the "linspace(0, used_freq, F)" operation gives a 1025 x 1 vector
插值似乎是三次插值 (k = 3)。
我只是不知道如何在 MATLAB 中将所有这些构造成一个 for 循环。 到目前为止,我尝试过这样的事情:
matlab loop
f代表操作“linspace(0, used_freq, F)'” 注意在 Matlab 中,它必须用 ' .
转置我试图让它在 Matlab 中工作,我不确定该怎么做,可能是在循环中缺少一些索引,或者可能需要转置某些 vectors/matrices 或组合那些。
T = 1968,
F = 1025,
used_freq = 22050,
下面这行是错误的说法。 freqs 的高维必须小于 F。我可以补充一点 freqs 必须包含索引,而不是频率。
freqs = 1621 x 1 vector - wrong
freqs = F< x 1 vector - right
log_scale_spec = T x F matrix,
您可以删除下面的行,因为 _cent_spec_ 在循环外求值
cent_spec=zeros(T,F<)
f=linspace(0, used_freq, F);
for t=1:T
Sp(:,t)=interp1(f,log_scale_spec(:,t),'cubic');
end
cent_spec=Sp(:,freqs);