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

 Accepted Answer

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 Comments

Thanks for comment but i cannot hear sound even with your changes you mentioned can rewrite complete code where you have made changes
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
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.
can you make changes in it to make it some pleasant sound plz
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)
i want to generate guitar chords from above code but the change you made doesn't generate guitar sound.
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.
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Audio Processing Algorithm Design in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!