Design of a Guitar Tab Player in MATLAB Background Lecture

Slides:



Advertisements
Similar presentations
| Page Angelo Farina UNIPR | All Rights Reserved | Confidential Digital sound processing Convolution Digital Filters FFT.
Advertisements

Tamara Berg Advanced Multimedia
Analog and Digital Signals AD/DA conversion BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Feb 5 Lesson 3.
Analysis of recorded sounds using Labview
Analog-to-Digital Converter (ADC) And
CMPS1371 Introduction to Computing for Engineers PROCESSING SOUNDS.
Pure Tones and the Sine Wave
0 - 1 © 2010 Texas Instruments Inc Practical Audio Experiments using the TMS320C5505 USB Stick “Sine Waves” Texas Instruments University Programme Teaching.
Sound test. Signals and waveforms What is a signal? Need not be electrical Morse Speech Video Contains information.
Music and Mathematics are they related?. What is Sound? Sound consists of vibrations of the air. In the air there are a large number of molecules moving.
The frequency spectrum
Lecture 9: D/A and A/D Converters
SIMS-201 Characteristics of Audio Signals Sampling of Audio Signals Introduction to Audio Information.
IT-101 Section 001 Lecture #8 Introduction to Information Technology.
Digital audio recording Kimmo Tukiainen. My background playing music since I was five first time in a studio at fourteen recording on my own for six months.
Chapter 15 Sound 15.1 Properties of Sound 15.2 Sound Waves
Lecture 2: Wave Phenomena II and Adding up waves.
EE2F1 Speech & Audio Technology Sept. 26, 2002 SLIDE 1 THE UNIVERSITY OF BIRMINGHAM ELECTRONIC, ELECTRICAL & COMPUTER ENGINEERING Digital Systems & Vision.
© 2010 Pearson Education, Inc. Conceptual Physics 11 th Edition Chapter 21: MUSICAL SOUNDS Noise and Music Musical Sounds Pitch Sound Intensity and Loudness.
Fundamentals of Digital Audio. The Central Problem n Waves in nature, including sound waves, are continuous: Between any two points on the curve, no matter.
Physics 434 Module 3 - T. Burnett 1 Physics 434 Module 3 Acoustic excitation of a physical system.
Basic Concepts: Physics 1/25/00. Sound Sound= physical energy transmitted through the air Acoustics: Study of the physics of sound Psychoacoustics: Psychological.
Numerical algorithms for power system protection Prof. dr. sc. Ante Marušić, doc. dr. sc. Juraj Havelka University of Zagreb Faculty of Electrical Engineering.
Computer Science 121 Scientific Computing Winter 2014 Chapter 13 Sounds and Signals.
Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering.
EE 319K Introduction to Microcontrollers
COMP Representing Sound in a ComputerSound Course book - pages
Motivation Music as a combination of sounds at different frequencies
Art 321 Sound, Audio, Acoustics Dr. J. Parker. Sound What we hear as sound is caused by rapid changes in air pressure! It is thought of as a wave, but.
CSC361/661 Digital Media Spring 2002
ACOE2551 Microprocessors Data Converters Analog to Digital Converters (ADC) –Convert an analog quantity (voltage, current) into a digital code Digital.
Computer Some basic concepts. Binary number Why binary? Look at a decimal number: 3511 Look at a binary number: 1011 counting decimal binary
15.1 Properties of Sound  If you could see atoms, the difference between high and low pressure is not as great.  The image below is exaggerated to show.
Fourier series. The frequency domain It is sometimes preferable to work in the frequency domain rather than time –Some mathematical operations are easier.
Wireless and Mobile Computing Transmission Fundamentals Lecture 2.
Harmonics. Introduction Harmonic is obtained by a method of playing stringed instruments - playing the instrument while holding a finger against the string,
COSC 1P02 Introduction to Computer Science 4.1 Cosc 1P02 Week 4 Lecture slides “Programs are meant to be read by humans and only incidentally for computers.
Day 6 Exam I is on Thursday. Be sure to attend lab this week.
Signals CY2G2/SE2A2 Information Theory and Signals Aims: To discuss further concepts in information theory and to introduce signal theory. Outcomes:
 Suppose you are trying to get a swing in motion.  You've probably seen "beginners" kick their feet out at random frequencies, causing the swing to.
Georgia Institute of Technology Introduction to Processing Digital Sounds part 1 Barb Ericson Georgia Institute of Technology Sept 2005.
1 Introduction to Information Technology LECTURE 6 AUDIO AS INFORMATION IT 101 – Section 3 Spring, 2005.
Complex Auditory Stimuli
Sonia Hingorany & Liza Cyriac EE113D – Professor Rajeev Jain & TA Rick Huang– Winter 2008.
Chapter 21 Musical Sounds.
Recording Arts…Audio Sound Waves Fall What does this all mean to you in this class? You are always working with sound waves – it is important to.
Signal Analyzers. Introduction In the first 14 chapters we discussed measurement techniques in the time domain, that is, measurement of parameters that.
3.3 Waves and Stuff Science of Music 2007 Last Time  Dr. Koons talked about consonance and beats.  Let’s take a quick look & listen at what this means.
SOUNDS RECORDING AND REPRODUCTION The Volume of the Wave n The Amplitude is a measure of volume n The wave pink is softer than the blue wave. n It represents.
12-3 Harmonics.
Design of a Guitar Tab Player in MATLAB Summary Lecture Module 1: Modeling a Guitar Signal.
15.1 Properties of Sound. Chapter 15 Objectives  Explain how the pitch, loudness, and speed of sound are related to properties of waves.  Describe how.
Adding waves can be positive or negative.. Superposition  When two (or more) waves interfere (meet… they’re at the same place at the same time) the resultant.
Sound Part II  Music What is the study of sound called?  Acoustics.
Section Vocabulary  Pitch- the highness or lowness of sound  Hertz- unit used to measure the frequency of a sound wave  Octave- A series of 8 notes.
Fourier Analysis Patrice Koehl Department of Biological Sciences National University of Singapore
Fourier Series Prof. Brian L. Evans
COMPUTER NETWORKS and INTERNETS
MECH 373 Instrumentation and Measurements
MECH 373 Instrumentation and Measurements
Introduction to Digital Audio
Chapter 16: Sound HW problems: Chapter 16: Pb.2, Pb.18, Pb.24, Pb.35, Pb.40, Pb.62: Due Wed., Jan. 17.
MECH 373 Instrumentation and Measurements
Introduction to Digital Audio
Introduction to Digital Audio
Introduction to Digital Audio
Lecture 2: Frequency & Time Domains presented by David Shires
Analog to Digital Encoding
Chapter 16: Sound.
Introduction to Digital Audio
Presentation transcript:

Design of a Guitar Tab Player in MATLAB Background Lecture Module 1: Modeling a Guitar Signal

Multitude of guitar tabs on the Internet Some are good some are not The Problem Multitude of guitar tabs on the Internet Some are good some are not Wasted time and frustration for an amateur guitar player trying to learn a song Having a way to check quickly if a guitar tab is good or not

Typical Electric Guitar Low E D frets g b High e to amplifier magnetic pickups A typical electric guitar has 6 strings and 24 frets

e|------------------------1-0----------| Guitar Tablature e|------------------------1-0----------| B|----------------------------1-3p1-0--| G|-------------------------------------| D|------------------3-2-0--------------| A|------------3-2-0--------------------| E|--0-0-3-2-0--------------------------| Guitar tablature is a form of musical notation that is well suited for playing the guitar. It shows the six strings of the guitar. The number and its location corresponds to the string to pluck and the fret where to place the finger. Fret 0 represents the case where one leaves the string open

Playing the Guitar Tablature B|----------------------------1-3p1-0--| G|-------------------------------------| D|------------------3-2-0--------------| A|------------3-2-0--------------------| E|--0-0-3-2-0--------------------------| Low E fret 2 Low E (open string) Low E (open string) Low E fret 3 Low E A D G B High e

Guitars and Guitar Signals What Do We Know About Guitars and Guitar Signals

Guitar String Vibrations First Harmonic (Fundamental) Second Harmonic Third Harmonic The string must make an integer number of half sines between the two points it is attached too

Fundamental Frequency for a String f0 is the frequency of the sound signal in Hertz (Hz) m is the linear mass of the string given in kilograms per meter (kg/m) L is the length of the string in meters (m) T is the tension on the string giving in Newtons (N) A guitar string is tuned by tightening or loosening the string (increasing or decreasing T) The frequencies produced by a bass are lower than that of a guitar. This is why a bass has longer strings than a guitar (greater L value).

Fundamental Frequencies for a Guitar String Fundamental Frequency Low E 82 Hz A 110 Hz D 147 Hz G 196 Hz B 247 Hz High e 330 Hz The guitar will be tuned when the strings produce the fundamental frequencies above. (The fundamental frequencies for a bass are 41, 55, 73, and 98Hz)

Fundamental Frequencies with Frets fret 3 fret 2 fret 1 When placing the finger on a fret, the sound has a higher pitch (higher frequency) than that of the open string. The frets are designed such that the fundamental frequencies produced are: where f0 string = 82, 110, 147, 196, 247, or 330Hz depending on the string. Example: Plucking the Low E string with the finger on the second fret produces a sound with fundamental frequency:

How Can the Guitar Signal Be Modeled?

Mathematical Formulation: Pure Tone or Sinewave A T0 Fundamental Period t -A Mathematical Formulation:

Single Sinewave Model String Guitar Recording Low E 82 Hz A 110 Hz D 147 Hz G 196 Hz B 247 Hz High e 330 Hz Modeling the sound of a guitar string using a single sinewave does not sound satisfactory. It seems that the guitar string has a higher “pitch” than the single sinewave.

Adding Several Sinewaves (Fundamental and Harmonics)

Signal Obtained from Adding Sinewaves

Issues How many harmonics to use? Are the amplitudes all equal to 1? Does the signal obtained look like the actual signal? More importantly: Does the signal obtained sound like the actual signal? Take measurements to check/improve the model

Measuring Actual Guitar Signals Using a Computer Sound Card guitar output jack plug PC/laptop microphone or line input jack connector

Sampling in an Analog Signal (MIC/Line Input): Analog to Digital Conversion Sampling Theorem: One must sample at least twice as fast as the highest frequency contained in the signal

Producing an Analog Signal (Speaker Output): Digital to Analog Conversion

Sound Card Control (Volume Control - Playback) D/A Control Programs->Accessories->Entertainment->Volume Control Typical sound cards can produce electrical signals up to +/- 2 volts maximum. This explains why one needs external speakers with power supply for louder sounds.

Sound Card Control (Volume Control - Recording) A/D Control Signals at the MIC or line input should not exceed +/- 150 mV

Microsoft Windows Sound Recorder Programs->Accessories->Entertainment->Sound Recorder Sound signals are most commonly stored into .wav files. The samples are obtained using Pulse Code Modulation (PCM). One has the flexibility to specify the sampling frequency and the number of bits

Measurement of the Open Low E String

Three Sinewaves Model actual recording model

Issues It sounds better than the single sinewave model but it is difficult to tell from the time waveform: How many harmonics to use The amplitudes of the sinewaves to use If the frequencies of the sinewaves are as expected The Fourier Transform can be used to show the frequencies and amplitudes contained in the signal. The results are shown in a what is called the Frequency Spectrum graph

Frequency Spectrum of Harmonic Signals Single sinewave (single tone) Frequency Spectrum Math Formula Several sinewaves (fundamental and harmonics) Frequency Spectrum Math Formula

Measured Frequency Spectrum of the Open Low E String f = 82 Hz, amplitude = 0.7251 f = 164 Hz, amplitude = 0.9789 f = 246 Hz, amplitude = 1.0000 f = 328 Hz, amplitude = 0.4764 fundamental (82 Hertz) second harmonic (164 Hertz) third harmonic (246 Hertz) forth harmonic (328 Hertz) fifth harmonic (410 Hertz) becoming negligible The measured frequency spectrum is obtained by running a Fast Fourier Transform (FFT) program on the time samples of the guitar string. One can clearly see the fundamental and harmonics, their frequencies and amplitudes.

Other Measured Frequency Spectrums Frequency spectrum of a human voice (somewhat harmonic) Frequency spectrum of a drum type sound (not harmonic)

Measurement Based Model

Mathematical Model of an Open String The guitar signal is modeled as a sum of several sinewaves (fundamental and harmonics): The fundamental frequency f0 depends on the string and is given for a tuned guitar by: String f0 Low E 82 Hz A 110 Hz D 147 Hz G 196 Hz B 247 Hz High E 330 Hz The amplitudes A1, A2, A3, etc of the sinewaves in the model are obtained by running the FFT program on the measured time samples of the open string as shown in the next slide.

Getting the Amplitudes A1, A2, A3, etc for the Model Run the FFT program on the measurement .wav file of the open string. Then locate the peaks and report the fundamental/harmonics amplitudes A1, A2, A3, A4, etc using the Frequency Spectrum graph produced. Check that depending on the string, f0 = 82, 110, 147, 196, 247 or 330Hz.

Modeling any String/Fret Combination The model can be extended to any of the string/fret combinations. The main difference comes from the fundamental frequency to use. For example calling fx the fundamental frequency for a string with a given fret gives the general model: Note that the general model also works for open strings since String f0 Low E 82 Hz A 110 Hz D 147 Hz G 196 Hz B 247 Hz High E 330 Hz

Design Choices To complete the general model, one needs to define the sinewave amplitudes A1, A2, A3, etc. There are two straightforward methods: Take samples of all 144 string/fret combinations and extract the sinewave amplitudes from the measured frequency spectrums obtained running the FFT program. Reuse the same sinewave amplitudes as those obtained for the open strings. Pros/Cons: Solution 1 is more accurate than solution 2 but will require a lot more work and a lengthier program. Solution 2 should be sufficient for the application: playing quickly guitar tabs to check if the tab is valid or not.

Effects of Decay The general model does not go down after some time as does the actual guitar string signal. We need to add something in the model that can make the signal go down over time.

Exponential Decay The previous model is multiplied by an exponential function so that its amplitude will decrease over time: The exponential function starts at 1 when t = 0 and drops to 0.37 when t = T. Therefore to estimate T, one checks to see when the time waveform has dropped from 1 to 0.37. T about 1.8 seconds 0.37

Some Useful MATLAB Functions

Reading a .WAV File and Plotting the Waveform clc; clear; close all; filename = input('wav file name => ','s'); % Enter file name from keyboard [vt, Fs, nbits] = wavread(filename); % vt has the amplitude samples % Fs has the sampling rate Ts = 1/Fs; % Compute sampling time Ts N = length(vt); % N is the number of samples t = Ts*[0:1:N-1]; % Form times values using Ts figure(1) % Plot vt versus t plot(t, vt) grid on title('v(t)')

Generating a Sinewave and Saving It in a .WAV File clc; clear; close all; Fs = 8000; % Set the sampling rate Fs Ts = 1/Fs; % Compute sampling time Ts nbits = 16; % Set the number of bits nbits N = 800; % Set the number of points N t = Ts*[0:1:N-1]; % Form the time values f0 = 10; % Set the sinewave frequency f0 vt = 2*sin(2*pi*f0*t); % Generate the sinewave filename = input('wav file name => ','s'); % Get the filename from keyboard wavwrite(vt, Fs, nbits, filename); % Save the sinewave vt in the .wav file

Clipping Issues Clipping One should scale the amplitude of the waveform to fit between +/- 1 before saving it to the .wav file. If not the waveform will be “clipped” as shown below. Clipping

Fixing the Clipping Issue clc; clear; close all; Fs = 8000; Ts = 1/Fs; nbits = 16; N = 800; t = Ts*[0:1:N-1]; f0 = 10; vt = 2*sin(2*pi*f0*t); vt = vt/max(vt); % Divide vt by % the maximum value in vt filename = input('wav file name => ','s'); wavwrite(vt, Fs, nbits, filename);

Fast Fourier Transform (FFT) The MATLAB function called fft.m can be used to compute the frequency spectrum of a signal when the time waveform samples are provided. filename = input('wav file name => ','s'); [vt, Fs, nbits] = wavread(filename); Ts = 1/Fs; N = length(vt); df = Fs/N; t = Ts*[0:1:N-1]; f = df*[0:1:N-1]; % Create appropriate frequency values Vf = fft(vt); % Computes the FT values (complex) Vfnorm = Vf/max(abs(Vf)); % Normalize to +/- 1 figure(1) plot(f, abs(Vfnorm), 'k') % Plot the magnitude versus frequency axis([0 Fs/2 0 1]) % Limit plot from 0 to Fs/2 (x-axis) grid on % and from 0 to 1 (y-axis) legend('|Vnorm(f)|') xlabel('f (Hz)')

Playing Sounds To play sounds directly in MATLAB, one can use the functions sound.m, soundsc.m, or wavplay.m SOUND(Y,FS) sends the signal in vector Y (with sample frequency FS) out to the speaker. Values in Y are assumed to be in the range -1.0 <= y <= 1.0. Values outside that range are clipped. Stereo sounds are played, on platforms that support it, when Y is an N-by-2 matrix. SOUNDSC(Y,...) is the same as SOUND(Y,...) except the data is scaled so that the sound is played as loud as possible without clipping. WAVPLAY(Y,FS) sends the signal in vector Y with sample frequency of FS Hertz to the Windows WAVE audio device. Standard audio rates are 8000, 11025, 22050, and 44100 Hz. For stereo playback, Y should be an N-by-2 matrix. Values in Y are assumed to be in the range -1.0 <= y <= 1.0. Values outside that range are clipped.

Example of Playing Sounds clc clear close all Fs = 8000; % Sampling rate Fs Ts = 1/Fs; % Compute sampling time Ts N = 8000; % 8000 pts last 1 second t = Ts*[0:1:N-1]; % Form t vector with values f0 = 100; % separated by Ts seconds vt = 1*sin(2*pi*f0*t);% Compute the samples of % the sinewave sound(vt, Fs) % Send it to the sound card

Example of Playing Stereo Sounds Fs = 8000; Ts = 1/Fs; N = 8000; t = Ts*[0:1:N-1]; f1 = 100; f2 = 500; vleft = 1*sin(2*pi*f1*t); vright = 1*sin(2*pi*f2*t); vt = [vleft' vright']; % vt has two columns % vleft and vright sound(vt, Fs)