利用插值和repmat变换倍频程信号的频率,并在matlab中实现



我使用的是Octave 3.8.1,它类似于matlab,我正试图使用插值和repmat来改变信号的频率(,因为这样做太快了(.01秒),而且我必须一次创建28000多个我可以将变量num_per_sec更改为任何整数,但如果我试图将其更改为2.1或任何包含小数的值,我会出错"错误:整形:无法将44100x2数组整形为92610x1数组错误:从:第10行(repmat行)调用"有人对此或其他建议有解决方案吗?

注意:请注意,ya是一个简单的测试方程我没有方程来处理,只有信号来处理,所以仅仅改变频率变量是行不通的

参见下面的代码:

clear,clc
fs = 44100;                   % Sampling frequency
t=linspace(0,2*pi,fs);
freq=1;
ya = sin(freq*t)';  %please note that this is a simple test equation I won't have equations just the signal to work with.
num_per_sec=2 %works
%num_per_sec=2.1 %doesn't work
yb=repmat(ya,num_per_sec,1);%replicate matrix 
xxo=linspace(0,1,length(yb))'; %go from 0 to 1 sec can change speed by incr/decr 1
xxi=linspace(0,1,length(ya))'; %go from 0 to 1 sec and get total samplerate from total y value
yi_t=interp1(xxo,yb,xxi,'linear');
plot(yi_t)

您正试图用浮点数字调用repmat。很明显,它不会按照你想要的方式工作。repmat的预期操作是将特定维度复制整数次

因此,我可以建议的一件事是,也许截断不等于1的倍数的信号,并将其叠加在复制信号的末尾。例如,如果你想复制一个信号2.4次,你可以正常地复制整个信号两次,然后将信号长度的40%堆叠到阵列的末端。因此,您需要对信号总持续时间的40%进行采样,并将其放置在复制信号的末尾。

由于您有采样频率,因此这会"告诉"您每秒应包含多少个样本信号。因此,计算出你有多少整数倍,然后通过将这个百分比乘以你的采样频率来确定部分信号由多少个样本组成。然后,你可以从中采样,并将其叠加在信号的末尾。例如,在2.4的例子中,我们将执行floor(0.4*fs)来确定从信号开始的样本总数,我们将需要提取该样本以将其放置在复制信号的末尾。

类似这样的东西:

%// Your code
clear, clc
fs = 44100; %// Define sampling frequency                 
t=linspace(0,2*pi,fs);
freq=1;
ya = sin(freq*t)'; %// Define signal
num_per_sec=2.1; %// Define total number of times we see the signal
%// New code
%// Get total number of integer times we see the signal
num_whole = floor(num_per_sec);
%// Replicate signal
yb=repmat(ya,num_whole,1);
%// Determine how many samples the partial signal consists of
portion = floor((num_per_sec - num_whole)*fs);
%// Sample from the original signal and stack this on top of replicated signal
yb = [yb; ya(1:portion)];
%// Your code
xxo=linspace(0,1,length(yb))'; 
xxi=linspace(0,1,length(ya))'; 
yi_t=interp1(xxo,yb,xxi,'linear');