(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:2011 Fall ECE 438 Boutin]][[Category:2011 Fall ECE 438 Boutin]]
+
<br>
  
=Audio Signal Generating and Processing Project=
+
= Audio Signal Generating and Processing Project =
 +
Student project for [[ECE438]]
 +
----
  
- '''Abstract''' -
+
Introduction:
  
This project is intent to analysis different musical instrument's sound, and try to create artificial musical instrument sounds to play a piece.
+
:Listen to this piece of music.
 +
::[[Media:Audio_Signal_Generating_and_Processing_Project_final_verison.wav‎]]
 +
:Just soso, right? but this is generated by computer software by MATLAB.
 +
----
 +
- '''Abstract''' -
  
First, by looking at the Fourier domain, one can and measure the amplitude of each harmonics. The intention is trying to produce similar amplitude harmonic cosine functions, and mix all the waveform together to construct a simulated instrument voice.
+
:This project is intent to analysis different musical instrument's sound, and try to create artificial musical instrument sounds to play a piece.  
  
- '''Procedure''' -
+
----
 +
- '''Procedure''' -  
  
First a couple of sound files are inspected. Particularly this  [http://www.daimi.au.dk/~jones/dsp/sounds/singlenote/Piano.ff.F3.wav single note piano sound] was used.
+
: A record of limited number of keys on a piano keyboard was used. The original sample is here.
Take the FFT in MATLAB, the frequency domain of the graph looks like this.
+
::[[Media:Orginal_sound_sample.wav‎]]
  
 +
: After the first frustrating method, I decided to up/down sample the keys by right order, then place them in right key.
  
 +
: According to modern music theory of interval, each intervals are equally spaced, each octave is equally spaced in to 12 intervals. A octave higher means twice the frequency. So, each interval is spaced by frequency ration of  <math> 2^{ \frac{1}{12}} = 1.05946309</math>
 +
:But here comes a problem for up/down sample, it can only up/down sample by a integer factor. One can't upsampling by 1.05946309.
 +
::However, inspect the rational number <math> { \frac{18}{17}} = 1.05882353</math> , that is relatively close to 1.05946309.
 +
::Next closer fraction is <math> { \frac{107}{101}} =  1.059405941</math>, But this fraction doesn't change too much accuracy, but as we can see below, it increase the computation steps rapidly. So I choose  <math> { \frac{18}{17}} = 1.05882353</math>  as the approximate factor.
  
[[Image:Fft_piano.png|500px]]
+
:Next, use this fraction, apply the following:
 +
:: if a note half-step above the original is desired, then upsample by 17, then down sample by 18, call this as "move up"
 +
:::In this case, the signal is preserved, but at a lower sampling frequency. If play at the original frequency, then the note half-step above is played.
 +
:: if a note half-step below the original is desired, then upsample by 18, then down sample by 17, call this as "move down"
 +
:::In this case, the signal is preserved, but at a higher sampling frequency. If play at the original frequency, then the note half-step below is played.
  
Then one can record all the amplitude of different harmonics.
+
:For each interval(from lower C to higher C),
Also notice that the sound amplitude is decreasing as time goes by. A decreasing exponential envelope is require for the signal to sound more like a real instrumental voice.
+
:take the lower C, "move up" by step recursively, then get a map of full chromatic scale, define map1, with the exact timber of the lower C;
the amplitude of the waveform of the soundtrack is 4 at very beginning, decreased to 0.5 after 1s and goes to 0.5 after 3 seconds. So an envelope function
+
:take the higher C, "move down" by step recursively, then get a map of full chromatic scale, with the exact timber of the higher C;
<math> e^{(-2.07944154*t)} = e^{(-2.07944154/samplerate*n)}  </math>
+
:if we pick higher part of the scale as map1, lower part map2, then at the junction, the timber suddenly changed, makes the sound very unnatural.  
 +
:: You can hear it in here [[Media:Audio_Signal_Generating_and_Processing_Project_Timber_before.wav]]
  
Next thing need to be done, is design a pattern that plays multiple notes at the same time.
+
:Instead, apply the following method:
The first guess is just sum up all the harmonics and get the result. But actually this doesn't work.
+
::a given note is contribute by both map1 and map2, and proportional to the end point.
The sound of a minor three interval sounds like this.
+
::For example, the note C# is constructed by
 +
:: <math> {C^\#} =  { \frac{11}{12}}*map_1(C^\#)  + { \frac{1}{12}}*map_2(C^\#)</math>
 +
:: <math> F =  { \frac{7}{12}}*map_1(F) + { \frac{5}{12}}*map_2(F) </math>
 +
:: <math> A =  { \frac{3}{12}}*map_1(A) + { \frac{9}{12}}*map_2(A) </math>
 +
::This take cares of the timbre difference. Minor detail is still not perfect, but maybe just change the original signal can improve it. It is a very poor recorded signal.
  
Note_A:This is a cosine function with a frequency = 440Hz.
+
----
  
Namely Note_A = cos(440*2*pi*t) = cos(440*2*pi*n/Sample_Rate);
+
:Error analysis:
 +
::The ratio I pick is 1.05882353 versus the accurate factor = 1.05946309;
 +
::Error factor is <math>\frac{1.05946309}{1.05882353} = 1.00060403</math>
 +
::Since this error accumulates, and I am generating 12 notes with one real notes, take <math>1.00060403^{12} = 1.00727253</math> as the maximum error factor.
 +
::This difference is <math>log_{1.05946309}(1.00727253) = 0.12544891</math>, about 1/8 of a step;
 +
::In modern music, pitch was divided in to the term "cents" to measure smaller difference in pitch. Each step contains 100 cents.
 +
::In this case, the error is within 13 cents. For pure frequency, the smallest pitch difference human ears can distinguish is about 6~7 cents.
 +
::In string musical instrument, human can distinguish about 12~20 cents.
 +
::These data need to be verify, but on my opinion, that data is the best record of all human being. I have a experiment with my music teacher, I myself can only distinguish about 1/3 of a step in string instrument(about 35 cents), and even my music teacher can only distinguish about 1/4 of a step(about 25 cents)
 +
::On the other hand, a not well toned piano can easily go off 20 cents.
 +
::So I will claim that, this approach is acceptable in pitch level.
  
[[Media:Audio_Signal_Generating_and_Processing_Project_FILES_Note_A.wav]]
+
----
  
Note_C:This is a cosine function with a frequency = 523.251131Hz.  
+
:Hence, we have a full piano keyboard by now.
 +
:The data was saved in a matrix into a .mat file.
 +
:A script was wrote, that use a special pattern of pitch and rhythm matrix to call the corresponding column of the keyboard matrix.
 +
:Then combines the different duration and pitch notes in to a song, as you heard at the beginning.
  
Namely Note_A = cos(523.251131*2*pi*t) = cos(523.251131*2*pi*n/Sample_Rate);
 
  
[[Media:Audio_Signal_Generating_and_Processing_Project_FILES_Note_C.wav]]
 
  
Distorted m3 interval: this is the sum up of the Note_A and Note_C directly.
+
::There's another method I tried, which is to generate signal directly by inspecting a musical instrument's FFT, but this method doesn't turn up good result. Documentation can be found here:
  
Which sounded distorted.
+
[[Audio_Signal_Generating_and_Processing_Project%2C_Previous_method]]
  
[[Media:Audio_Signal_Generating_and_Processing_Project_FILES_failed_m3_interval.wav]]
+
[[2011 Fall ECE 438 Boutin|Back to 2011 Fall ECE 438 Boutin]]  
  
 
+
[[Category:2011_Fall_ECE_438_Boutin]]
 
+
[[Category:bonus point project]]
After some research reading online materials about mixing audios, several algorithms are tried, but a clear mix sound is still not founded. An article online mentioned that some how MATLAB doesn't allow a sound vector's amplitude to go above. As long as an coefficient less then one is multiplied to each terms, the sum of the waveform does construct a nice sound of mixed audio.
+
[[Category:ECE438]]
 
+
Here is a mixed C chord, consisting C,G,c,e1 four notes.
+
 
+
[[Media:Audio_Signal_Generating_and_Processing_Project_FILES_C_chord.wav‎]]
+
 
+
As a testing, I wrote an script that plays the first two lines of Parable's piece <Canon>.
+
 
+
[[Media:Audio_Signal_Generating_and_Processing_Project_FILES_canon_pure_frequency_with_chord.wav]]
+
 
+
 
+
 
+
 
+
 
+
An analysis is performed that a simulated piano voice is produced, according to the chart above. But it doesn't sound as expected. It is distorted and doesn't sound like a real piano. A better harmonic level is needed to adjust the sound.
+
 
+
Here is the file that contains all different harmonics.
+
 
+
Note that, the file contains only first harmonic, is exactly the same as the file produced by pure cosine wave.
+
 
+
As more harmonics added in, the sound become richer and more emotion, but not quite as the direction that is desired. Again, a better harmonic level is needed.
+
[[Media:Audio_Signal_Generating_and_Processing_Project_Piano_sound_with_Different_harmonics.zip]]
+
 
+
 
+
I have tried multiple piano sound files to do the FFT, take different period of the sound to do small pieces fft, but still not getting a good result. Any one has a suggestion what should I do to analysis the harmonics?
+
Thanks!
+
 
+
 
+
All Matlab files can be download here.
+
[[Media:Audio_Signal_Generating_and_Processing_Project_FILES_MATLAB_FILES.zip‎]]
+
 
+
 
+
 
+
[[ 2011 Fall ECE 438 Boutin|Back to 2011 Fall ECE 438 Boutin]]
+

Latest revision as of 06:19, 21 March 2013


Audio Signal Generating and Processing Project

Student project for ECE438


Introduction:

Listen to this piece of music.
Media:Audio_Signal_Generating_and_Processing_Project_final_verison.wav‎
Just soso, right? but this is generated by computer software by MATLAB.

- Abstract -

This project is intent to analysis different musical instrument's sound, and try to create artificial musical instrument sounds to play a piece.

- Procedure -

A record of limited number of keys on a piano keyboard was used. The original sample is here.
Media:Orginal_sound_sample.wav‎
After the first frustrating method, I decided to up/down sample the keys by right order, then place them in right key.
According to modern music theory of interval, each intervals are equally spaced, each octave is equally spaced in to 12 intervals. A octave higher means twice the frequency. So, each interval is spaced by frequency ration of $ 2^{ \frac{1}{12}} = 1.05946309 $
But here comes a problem for up/down sample, it can only up/down sample by a integer factor. One can't upsampling by 1.05946309.
However, inspect the rational number $ { \frac{18}{17}} = 1.05882353 $ , that is relatively close to 1.05946309.
Next closer fraction is $ { \frac{107}{101}} = 1.059405941 $, But this fraction doesn't change too much accuracy, but as we can see below, it increase the computation steps rapidly. So I choose $ { \frac{18}{17}} = 1.05882353 $ as the approximate factor.
Next, use this fraction, apply the following:
if a note half-step above the original is desired, then upsample by 17, then down sample by 18, call this as "move up"
In this case, the signal is preserved, but at a lower sampling frequency. If play at the original frequency, then the note half-step above is played.
if a note half-step below the original is desired, then upsample by 18, then down sample by 17, call this as "move down"
In this case, the signal is preserved, but at a higher sampling frequency. If play at the original frequency, then the note half-step below is played.
For each interval(from lower C to higher C),
take the lower C, "move up" by step recursively, then get a map of full chromatic scale, define map1, with the exact timber of the lower C;
take the higher C, "move down" by step recursively, then get a map of full chromatic scale, with the exact timber of the higher C;
if we pick higher part of the scale as map1, lower part map2, then at the junction, the timber suddenly changed, makes the sound very unnatural.
You can hear it in here Media:Audio_Signal_Generating_and_Processing_Project_Timber_before.wav
Instead, apply the following method:
a given note is contribute by both map1 and map2, and proportional to the end point.
For example, the note C# is constructed by
$ {C^\#} = { \frac{11}{12}}*map_1(C^\#) + { \frac{1}{12}}*map_2(C^\#) $
$ F = { \frac{7}{12}}*map_1(F) + { \frac{5}{12}}*map_2(F) $
$ A = { \frac{3}{12}}*map_1(A) + { \frac{9}{12}}*map_2(A) $
This take cares of the timbre difference. Minor detail is still not perfect, but maybe just change the original signal can improve it. It is a very poor recorded signal.

Error analysis:
The ratio I pick is 1.05882353 versus the accurate factor = 1.05946309;
Error factor is $ \frac{1.05946309}{1.05882353} = 1.00060403 $
Since this error accumulates, and I am generating 12 notes with one real notes, take $ 1.00060403^{12} = 1.00727253 $ as the maximum error factor.
This difference is $ log_{1.05946309}(1.00727253) = 0.12544891 $, about 1/8 of a step;
In modern music, pitch was divided in to the term "cents" to measure smaller difference in pitch. Each step contains 100 cents.
In this case, the error is within 13 cents. For pure frequency, the smallest pitch difference human ears can distinguish is about 6~7 cents.
In string musical instrument, human can distinguish about 12~20 cents.
These data need to be verify, but on my opinion, that data is the best record of all human being. I have a experiment with my music teacher, I myself can only distinguish about 1/3 of a step in string instrument(about 35 cents), and even my music teacher can only distinguish about 1/4 of a step(about 25 cents)
On the other hand, a not well toned piano can easily go off 20 cents.
So I will claim that, this approach is acceptable in pitch level.

Hence, we have a full piano keyboard by now.
The data was saved in a matrix into a .mat file.
A script was wrote, that use a special pattern of pitch and rhythm matrix to call the corresponding column of the keyboard matrix.
Then combines the different duration and pitch notes in to a song, as you heard at the beginning.


There's another method I tried, which is to generate signal directly by inspecting a musical instrument's FFT, but this method doesn't turn up good result. Documentation can be found here:

Audio_Signal_Generating_and_Processing_Project,_Previous_method

Back to 2011 Fall ECE 438 Boutin

Alumni Liaison

Questions/answers with a recent ECE grad

Ryne Rayburn