Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在matlab中将每个音符从一个音符分离到另一个音符_Matlab - Fatal编程技术网

如何在matlab中将每个音符从一个音符分离到另一个音符

如何在matlab中将每个音符从一个音符分离到另一个音符,matlab,Matlab,我得到了一些频率和音符来演奏音乐 tnote= [1,1,1/2,1/2,1,1/4,1/4,1/4,1/4,1/2,1/2,1/2,1/2,1]; fnote=[493.92, 587.36, 587.36, 659.28 659.28,784,741,784,741,784,587.36,587.36,659.28,659.28]; 我的采样频率 Fs= 8000; 我使用for循环,这样我就可以在正弦波中使用从tnote(1)到tnote(14)的每个t注释,以及从fnote(1)到f

我得到了一些频率和音符来演奏音乐

tnote= [1,1,1/2,1/2,1,1/4,1/4,1/4,1/4,1/2,1/2,1/2,1/2,1];
fnote=[493.92, 587.36, 587.36, 659.28 659.28,784,741,784,741,784,587.36,587.36,659.28,659.28];
我的采样频率

Fs= 8000;
我使用for循环,这样我就可以在正弦波中使用从
tnote(1)
tnote(14)
的每个t注释,以及从
fnote(1)
fnote(14)
的每个t注释

for i= 1:14

    if tnote(i)==1
        t=zeros(1,8001);
    elseif tnote(i)==1/2
        t=zeros(1,4001);
    elseif tnote(i)==1/4
        t=zeros(1,2001);
    end

t= 0:1/Fs:tnote(i);

   x= sin(2*pi*fnote(i)*t)
放歌

soundsc(x,11025)
    end

感觉这些音符是嵌套的。我不明白为什么笔记没有等待前一张笔记停止。如何在matlab中使其正确

这是因为当Matlab开始播放音符时,它不会等到结束。播放声音显然是一个独立的过程,Matlab会立即处理其余的程序。结果,音符堆积起来

要按顺序播放,您需要创建一个较大的
x
,其中包含一个接一个的所有音符,并在节目结束时播放该音符。例如:

tnote= [1,1,1/2,1/2,1,1/4,1/4,1/4,1/4,1/2,1/2,1/2,1/2,1];
fnote=[493.92, 587.36, 587.36, 659.28 659.28,784,741,784,741,784,587.36,587.36,659.28,659.28]

Fs= 8000;
x = [];
for i= 1:14
    if tnote(i)==1
        t=zeros(1,8001);
    elseif tnote(i)==1/2
        t=zeros(1,4001);
    elseif tnote(i)==1/4
        t=zeros(1,2001);
    end
    t= 0:1/Fs:tnote(i);
    x = [x sin(2*pi*fnote(i)*t)]; %// attach new note after the others
end
soundsc(x, Fs) %// you had 11025 instead of Fs. Was it intentional?

你也应该考虑预分配<代码> x>代码>,而不是在循环中增长。但在这种情况下,这可能不是很重要。

谢谢您的帮助。是的,是助理故意给的。他说“在soundsc()中使用播放频率11025”,但请注意,如果采样率和
Fs
不同,则播放的音符的实际频率将不会是
fnote
中的频率。它们将被缩放