我试图使用插值和重新匹配来改变信号的频率(因为它这么快就这样做(.01秒)并且我必须一次创建28000) I can change the variable num_per_sec to any whole number but if I try to change it to 2.1 or anything with a decimal in it I get an error "error: reshape: can't reshape 44100x2 array to 92610x1 array error: called from: line 10 (the repmat line)"有没有人为此工作或者另一个建议?
注意:请注意 ya 是一个简单的测试方程 I won't have equations to work with just the signal to work with so just changing the freq variable won't work.
见下面的代码:
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)
1 回答
您正尝试使用浮点数调用
repmat
. 显然它不会像你想象的那样工作 .repmat
的预期操作是复制特定维度 integer number of times .因此,我可以建议的一件事就是截断多次信号,该信号不会达到1,并在复制信号的末尾堆叠 . 例如,如果要复制2.4次信号,则通常会将整个信号复制两次,然后将信号长度的40%堆叠到数组末尾 . 因此,您需要采样信号总持续时间的40%,并将其置于复制信号的末尾 .
因为你有采样频率,这会告诉你信号应该包含多少 samples per second . 因此,计算出你有多少整数倍数,然后通过取这个百分比的最低值乘以你的采样频率来确定部分信号包含多少个样本 . 然后,您将从此进行采样,并在信号结束时将其叠加 . 例如,按照我们的2.4示例,我们将执行
floor(0.4*fs)
以确定从我们需要提取的信号开头的样本总数,以将其置于复制信号的末尾 .像这样的东西: