music piece creation with matlab
32 次查看(过去 30 天)
显示 更早的评论
I am carrying out a project where I should synthesize a piece of music where each musical note can be represented by a specific frequency.
where each note has a frequency equal to 2 ^ (1/12). assuming that the notes are in the octave which contains the frequencies in the range (220hz-440hz)
the question is how I can construct a discrete time signal of the notes of a piece of music. Use a sampling rate of 8000 samples per second and insert rests between notes.
and also how do I digitally shift up or down an octave, adjusting the duration of each note accordingly.
finally I should convert the volume of each note to a decrease over time, to make the music more realistic.
0 个评论
回答(3 个)
Star Strider
2022-4-5
I provided an outline on how to do exactly that in my Answer to your previous question: music piece with matlab .
Just change to :
A3 = 220;
A4 = 440;
A5 = 880;
Notes = A3*2^(1/12).^linspace(0, 11, 12); % Note Frequencies
Fs = 8000; % Sampling Frequency
t = linspace(0, Fs-1, Fs)/Fs; % Time Vector
NotesMatrix = sin(2*pi*t(:)*Notes); % Matrix Of One-Second Notes
for k = 1:size(NotesMatrix,2)
soundsc( NotesMatrix(:,k), Fs)
pause(1.1)
end
The code works. You will need to make the appropriate changes to make it work with your project.
.
0 个评论
Jan
2022-4-5
编辑:Jan
2022-4-5
You create the signal using sin() or cos() commands. 220Hz at 8000 Hz sampling frequency:
F = 8000;
t = linspace(0, 1, F); % 1 second
f = 220;
A = 1.0; % Amplitude
y = A * sin(2 * pi * f * t);
sound(y, F)
Shifting up by an octave means multiplying f by a factor of 2.
Decreasing the volume over the time:
A = linspace(1.0, 0.5, F); % From full to half
y = A .* sin(2 * pi * f * t); % .* is elementwise multiplication
"insert rests between notes" - I'm sure you are able to implement this.
2 个评论
Image Analyst
2022-4-6
I attach a demo where I create a warbling sound. Adapt it as needed, or ask a question about it if you have any.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!