(One intermediate revision by the same user not shown) | |||
Line 6: | Line 6: | ||
Put your content here . . . | Put your content here . . . | ||
− | As we all know, the timbre is determined by the waveform of the sound. To manipulate the sound of the piano, first need to find the Fourier Analysis of piano. | + | As we all know, the timbre is determined by the waveform of the sound. To manipulate the sound of the piano, first need to find the Fourier Analysis of piano. |
+ | |||
From this link | From this link | ||
[[Fourier_analysis_in_Music]] | [[Fourier_analysis_in_Music]] | ||
+ | |||
+ | <gallery> | ||
+ | File:Piano.jpg|Piano | ||
+ | </gallery> | ||
From this page, can get | From this page, can get | ||
+ | |||
a0=1 a1=0.1 a2=0.33 a3=0.06 a4=0.05 a5=0.045 a6=0 a7=0.02 a8=0.005 a9=0.005 a10=0 a11=0.005 a12=0.01 | a0=1 a1=0.1 a2=0.33 a3=0.06 a4=0.05 a5=0.045 a6=0 a7=0.02 a8=0.005 a9=0.005 a10=0 a11=0.005 a12=0.01 | ||
+ | |||
Then find the frequency of sound in music from this page | Then find the frequency of sound in music from this page | ||
+ | |||
https://pages.mtu.edu/~suits/notefreqs.html | https://pages.mtu.edu/~suits/notefreqs.html | ||
+ | |||
Use the frequency to make every sound of the piano. The basic signal is a cos signal. | Use the frequency to make every sound of the piano. The basic signal is a cos signal. | ||
+ | |||
To make the sound perfect, add the exp function before every sound. | To make the sound perfect, add the exp function before every sound. | ||
+ | |||
Finally find a music score and group these sounds together and use the sound command to play it. | Finally find a music score and group these sounds together and use the sound command to play it. | ||
+ | |||
The music score is like this page | The music score is like this page | ||
https://www.bethsnotesplus.com/2015/07/scarborough-fair.html | https://www.bethsnotesplus.com/2015/07/scarborough-fair.html | ||
Line 23: | Line 35: | ||
================================================================== | ================================================================== | ||
clc; | clc; | ||
+ | |||
clear; | clear; | ||
+ | |||
Fs = 22050; | Fs = 22050; | ||
+ | |||
delta = 1/Fs; | delta = 1/Fs; | ||
+ | |||
FC5 = 523.25; | FC5 = 523.25; | ||
+ | |||
FD5 = 587.33; | FD5 = 587.33; | ||
+ | |||
FE5 = 659.25; | FE5 = 659.25; | ||
+ | |||
FF5 = 698.46; | FF5 = 698.46; | ||
+ | |||
FG5 = 783.99; | FG5 = 783.99; | ||
+ | |||
FA5 = 880; | FA5 = 880; | ||
+ | |||
FB5 = 987.77; | FB5 = 987.77; | ||
+ | |||
+ | |||
d1 = 2; | d1 = 2; | ||
+ | |||
d05 = 1; | d05 = 1; | ||
+ | |||
d15 = 3; | d15 = 3; | ||
+ | |||
t1 = delta:delta:d1; | t1 = delta:delta:d1; | ||
+ | |||
t05 = delta:delta:d05; | t05 = delta:delta:d05; | ||
+ | |||
t15 = delta:delta:d15; | t15 = delta:delta:d15; | ||
+ | |||
+ | |||
PC4_1 = zeros(1,Fs*d1); | PC4_1 = zeros(1,Fs*d1); | ||
+ | |||
PD5_1 = zeros(1,Fs*d1); | PD5_1 = zeros(1,Fs*d1); | ||
+ | |||
PD5_05 = zeros(1,Fs*d05); | PD5_05 = zeros(1,Fs*d05); | ||
+ | |||
PA5_1 = zeros(1,Fs*d1); | PA5_1 = zeros(1,Fs*d1); | ||
+ | |||
PA5_05 = zeros(1,Fs*d05); | PA5_05 = zeros(1,Fs*d05); | ||
+ | |||
PE5_05 = zeros(1,Fs*d05); | PE5_05 = zeros(1,Fs*d05); | ||
+ | |||
PF5_05 = zeros(1,Fs*d05); | PF5_05 = zeros(1,Fs*d05); | ||
+ | |||
PD5_15 = zeros(1,Fs*d15); | PD5_15 = zeros(1,Fs*d15); | ||
+ | |||
+ | |||
p = [1 0.1 0.33 0.06 0.05 0.045 0 0.02 0.005 0.005 0 0.005 0.01]; | p = [1 0.1 0.33 0.06 0.05 0.045 0 0.02 0.005 0.005 0 0.005 0.01]; | ||
+ | |||
for n=1:length(p); | for n=1:length(p); | ||
+ | |||
%PC4_1 = PC4_1 + p(n)*exp((-1)*t1*4).*cos(2*pi*n*FC5*t1); % sythesize waveform | %PC4_1 = PC4_1 + p(n)*exp((-1)*t1*4).*cos(2*pi*n*FC5*t1); % sythesize waveform | ||
+ | |||
PD5_1 = PD5_1 + p(n)*exp((-1)*t1*3).*cos(2*pi*n*FD5*t1); | PD5_1 = PD5_1 + p(n)*exp((-1)*t1*3).*cos(2*pi*n*FD5*t1); | ||
+ | |||
PD5_05 = PD5_05 + p(n)*exp((-1)*t05*3).*cos(2*pi*n*FD5*t05); | PD5_05 = PD5_05 + p(n)*exp((-1)*t05*3).*cos(2*pi*n*FD5*t05); | ||
+ | |||
PD5_15 = PD5_15 + p(n)*exp((-1)*t15*3).*cos(2*pi*n*FD5*t15); | PD5_15 = PD5_15 + p(n)*exp((-1)*t15*3).*cos(2*pi*n*FD5*t15); | ||
+ | |||
PA5_1 = PA5_1 + p(n)*exp((-1)*t1*3).*cos(2*pi*n*FA5*t1); | PA5_1 = PA5_1 + p(n)*exp((-1)*t1*3).*cos(2*pi*n*FA5*t1); | ||
+ | |||
PA5_05 = PA5_05 + p(n)*exp((-1)*t05*3).*cos(2*pi*n*FA5*t05); | PA5_05 = PA5_05 + p(n)*exp((-1)*t05*3).*cos(2*pi*n*FA5*t05); | ||
+ | |||
PE5_05 = PE5_05 + p(n)*exp((-1)*t05*3).*cos(2*pi*n*FE5*t05); | PE5_05 = PE5_05 + p(n)*exp((-1)*t05*3).*cos(2*pi*n*FE5*t05); | ||
+ | |||
PF5_05 = PF5_05 + p(n)*exp((-1)*t05*3).*cos(2*pi*n*FF5*t05); | PF5_05 = PF5_05 + p(n)*exp((-1)*t05*3).*cos(2*pi*n*FF5*t05); | ||
+ | |||
end | end | ||
+ | |||
y = [PD5_1 PD5_05 PA5_1 PA5_05 PE5_05 PF5_05 PE5_05 PD5_15]; | y = [PD5_1 PD5_05 PA5_1 PA5_05 PE5_05 PF5_05 PE5_05 PD5_15]; | ||
+ | |||
sound(y, Fs); | sound(y, Fs); | ||
+ | |||
================================================================== | ================================================================== | ||
+ | |||
Copy this code into matlab can play a piece of music in Matlab. | Copy this code into matlab can play a piece of music in Matlab. | ||
[[ 2018 Spring ECE 301 Boutin|Back to 2018 Spring ECE 301 Boutin]] | [[ 2018 Spring ECE 301 Boutin|Back to 2018 Spring ECE 301 Boutin]] |
Latest revision as of 15:22, 21 April 2018
Manipulate piano sounnd with Matlab
Put your content here . . . As we all know, the timbre is determined by the waveform of the sound. To manipulate the sound of the piano, first need to find the Fourier Analysis of piano.
From this link Fourier_analysis_in_Music
From this page, can get
a0=1 a1=0.1 a2=0.33 a3=0.06 a4=0.05 a5=0.045 a6=0 a7=0.02 a8=0.005 a9=0.005 a10=0 a11=0.005 a12=0.01
Then find the frequency of sound in music from this page
https://pages.mtu.edu/~suits/notefreqs.html
Use the frequency to make every sound of the piano. The basic signal is a cos signal.
To make the sound perfect, add the exp function before every sound.
Finally find a music score and group these sounds together and use the sound command to play it.
The music score is like this page https://www.bethsnotesplus.com/2015/07/scarborough-fair.html
The final matlab code is like this.
======================================================
clc;
clear;
Fs = 22050;
delta = 1/Fs;
FC5 = 523.25;
FD5 = 587.33;
FE5 = 659.25;
FF5 = 698.46;
FG5 = 783.99;
FA5 = 880;
FB5 = 987.77;
d1 = 2;
d05 = 1;
d15 = 3;
t1 = delta:delta:d1;
t05 = delta:delta:d05;
t15 = delta:delta:d15;
PC4_1 = zeros(1,Fs*d1);
PD5_1 = zeros(1,Fs*d1);
PD5_05 = zeros(1,Fs*d05);
PA5_1 = zeros(1,Fs*d1);
PA5_05 = zeros(1,Fs*d05);
PE5_05 = zeros(1,Fs*d05);
PF5_05 = zeros(1,Fs*d05);
PD5_15 = zeros(1,Fs*d15);
p = [1 0.1 0.33 0.06 0.05 0.045 0 0.02 0.005 0.005 0 0.005 0.01];
for n=1:length(p);
%PC4_1 = PC4_1 + p(n)*exp((-1)*t1*4).*cos(2*pi*n*FC5*t1); % sythesize waveform
PD5_1 = PD5_1 + p(n)*exp((-1)*t1*3).*cos(2*pi*n*FD5*t1);
PD5_05 = PD5_05 + p(n)*exp((-1)*t05*3).*cos(2*pi*n*FD5*t05);
PD5_15 = PD5_15 + p(n)*exp((-1)*t15*3).*cos(2*pi*n*FD5*t15);
PA5_1 = PA5_1 + p(n)*exp((-1)*t1*3).*cos(2*pi*n*FA5*t1);
PA5_05 = PA5_05 + p(n)*exp((-1)*t05*3).*cos(2*pi*n*FA5*t05);
PE5_05 = PE5_05 + p(n)*exp((-1)*t05*3).*cos(2*pi*n*FE5*t05);
PF5_05 = PF5_05 + p(n)*exp((-1)*t05*3).*cos(2*pi*n*FF5*t05);
end
y = [PD5_1 PD5_05 PA5_1 PA5_05 PE5_05 PF5_05 PE5_05 PD5_15];
sound(y, Fs);
======================================================
Copy this code into matlab can play a piece of music in Matlab.