在matlab上调制音频波形时出现矩阵维数错误

Getting matrix dimension error while modulating audio waveform on matlab

我收到以下代码的矩阵维数错误。我在下面尝试做的是音频波形的调制,但我无法通过我指定的错误。我已经检查了 sample.wav 的长度并相应地调整了时间轴(t),但我一定做错了什么。如果有人能提供帮助,我将不胜感激。提前致谢!

 function [sm]= modulation(ss,fc,mtype)
ss= audioread('C:\Users\furka\Documents\MATLAB\sample.wav');     %audio waveform to be modulated is loaded.
plot(ss)
length(ss)
t=linspace(0,3e6,3161538);
fc= input('Carrier Frequency=');            %carrier frequency will be determined by the user


mtype= menu('Modulation type?','dsb','dsbsc','ssb','fm');           %modulation type will be determined by the user
%fs=44100;                                   %sampling frequency is determined for common audio waveform.(44.1kHz)
%t= 0:1/fs:(2e-5)-1/fs;

if mtype==1 
    ka= 0.7;
    sm= ss.*(1+ka*cos(2*pi*fc*t));
    plot(t,sm)

    elseif mtype==2                         %if doublesideband suppress carrier is selected the statements below will be carried out.

    y = ss.*cos(2*pi*fc*t);
    plot(y)
    % sm = fftshift(fft(abs(y)));
  %  frequency_axis= (-fs/2):(fs/length(sm)):(fs/2-fs/length(sm));
    %plot(frequency_axis,sm)

    elseif mtype==3
    sm=0.5*[ss.*cos(2*pi*fc*t)-hilbert(ss).*sin(2*pi*fc*t)];
    plot(t,sm)

    elseif mtype==4
     kf=0.7;            %frequency sensitivity.
    sm= cos(2*pi*fc*t+2*pi*kf*int(ss,t,0,t));
    plot(t,sm)
end
end

我无法访问为声音文件提供的 link 但是 3e6 秒的时间长度似乎是一个很长的声音。我估计大约需要 30 天。

使用 MathWorks 提供的 handel.mat 示例,我明白了。

load handel.mat
audiowrite('sample.wav', y, Fs);
[ss, Fs] = audioread('sample.wav');

t = linspace(0, length(ss) / Fs, length(ss));
t = t'; % this is important to match ss <-- this is your matrix dimension error I think
fc = 2000;
ka = 0.7
sm = ss .* (1 + ka * cos(2 * pi * fc * t));

维度不匹配的错误来自 linspace 输出是行向量而 audioread 输出是列向量。转置一个或另一个。在我的例子中:t = t'