Matlab code generate figure but does'nt create sound?

The following code create graphics figure but it don't create sound.
The code is following:
function Music()
Fs=44100;
T=1/Fs;
M = zeros(1,88);
for I=7:88,
M(I) = round(36.8*(2^(1/12))^(I-6));
end
Signal=[];
FrTm=[50,3;50,3;52,3;54,3;50,3;54,3;52,3;45,3;50,3;50,3;52,3;54,3;50,6;
49,3;1,3;50,3;50,3;52,3;54,3;55,3;54,3;52,3;50,3;49,3;45,3;47,3;49,3;50,6;
50,3;1,3;47,5;49,1;47,3;45,3;47,3;49,3;50,3;1,3;45,5;47,1;45,3;43,3;42,6;
45,3;1,3;47,5;49,1;47,3;45,3;47,3;49,3;50,3;47,3;45,3;50,3;49,3;52,3;50,6;
50,6];
t=[0:1/18:5];
for i=1:length(FrTm),
M(i)=FrTm(i,1);
Z=M(i);
data= sin(2*pi*Z/Fs*t);
Signal=[data;Signal];
end
stem(Signal);
sound(Signal,44100);
end

 採用された回答

Star Strider
Star Strider 2018 年 1 月 27 日

0 投票

You have two problems:
  1. you have to create ‘Signal’ as a column vector, not as a matrix,
  2. you need to multiply (amplify) it to make it audible.
In the loop, create ‘Signal’ as:
Signal = [data(:); Signal];
then to play it:
sound(Signal*25,Fs);
I can hear it with those changes. (It would also help if you made it longer, since it is only about 122 milliseconds long.)

8 件のコメント

Tayyab Shinwari
Tayyab Shinwari 2018 年 1 月 27 日
Thanks for comment but i cannot hear sound even with your changes you mentioned can rewrite complete code where you have made changes
Tayyab Shinwari
Tayyab Shinwari 2018 年 1 月 27 日
please change this code if you can
function Music()
Fs=44100;
T=1/Fs;
M = zeros(1,88);
for I=7:88,
M(I) = round(36.8*(2^(1/12))^(I-6));
end
Signal=[];
FrTm=[50 3;50,3;52,3;54,3;50,3;54,3;52,3;45,3;50,3;50,3;52,3;54,3;50,6; 49,3;1,3;50,3;50,3;52,3;54,3;55,3;54,3;52,3;50,3;49,3;45,3;47,3;49,3;50,6; 50,3;1,3;47,5;49,1;47,3;45,3;47,3;49,3;50,3;1,3;45,5;47,1;45,3;43,3;42,6; 45,3;1,3;47,5;49,1;47,3;45,3;47,3;49,3;50,3;47,3;45,3;50,3;49,3;52,3;50,6; 50,6];
for i=1:length(FrTm), %--------------------------------------------------- % complete the function
end
stem(Signal); sound (Signal, 44100);
end
Star Strider
Star Strider 2018 年 1 月 27 日
Here it is, including the 2 changes I made to it. I use the code you previously posted:
Fs=44100;
T=1/Fs;
M = zeros(1,88);
for I=7:88,
M(I) = round(36.8*(2^(1/12))^(I-6));
end
Signal=[];
FrTm=[50 3;50,3;52,3;54,3;50,3;54,3;52,3;45,3;50,3;50,3;52,3;54,3;50,6;
49,3;1,3;50,3;50,3;52,3;54,3;55,3;54,3;52,3;50,3;49,3;45,3;47,3;49,3;50,6;
50,3;1,3;47,5;49,1;47,3;45,3;47,3;49,3;50,3;1,3;45,5;47,1;45,3;43,3;42,6;
45,3;1,3;47,5;49,1;47,3;45,3;47,3;49,3;50,3;47,3;45,3;50,3;49,3;52,3;50,6;
50,6];
t=[0:1/18:5];
for i=1:length(FrTm),
for i=1:length(FrTm),
M(i)=FrTm(i,1);
Z=M(i);
data= sin(2*pi*Z/Fs*t);
Signal=[data(:);Signal];
end
end
stem(Signal);
soundsc(Signal, 44100);
Be sure the sound card on your computer is enabled, and that none of the outputs are muted. Consider using headphones.
I can easily hear it with my laptop and without headphones. It lasts for 7.2 seconds.
Tayyab Shinwari
Tayyab Shinwari 2018 年 1 月 27 日
can you make changes in it to make it some pleasant sound plz
Star Strider
Star Strider 2018 年 1 月 27 日
I have no idea what you want.
Try this:
Fs = 44100;
t = linspace(0, 5, Fs*5); % 5 Seconds
FreqVct = [1000 1500 2000]; % Vector Of Frequencies
Signal = sin(FreqVct' * t * 2*pi );
Signal = sum(Signal)';
soundsc(Signal, Fs)
Tayyab Shinwari
Tayyab Shinwari 2018 年 1 月 27 日
i want to generate guitar chords from above code but the change you made doesn't generate guitar sound.
Star Strider
Star Strider 2018 年 1 月 27 日
It can create the sound you want. You must define the frequencies in ‘FreqVct’ to be the correct frequencies for the guitar chords. Musical instruments also are nonlinear and have their own resonances, so unless you specifically model those acoustics, it will not sound exactly like a guitar, even if you get the frequencies correct.
Tayyab Shinwari
Tayyab Shinwari 2018 年 1 月 28 日
In the question the task is *to generate * guitar sound using these frequencies matrix and its duration is 3/18 and 6/18 unit of a duration.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by