Processing sounds
This presentation is the property of its rightful owner.
Sponsored Links
1 / 32

CMPS1371 Introduction to Computing for Engineers PowerPoint PPT Presentation


  • 89 Views
  • Uploaded on
  • Presentation posted in: General

PROCESSING SOUNDS. CMPS1371 Introduction to Computing for Engineers. The Physics Of Sound. Why do we hear what we hear? Sound is made when something vibrates. The vibration disturbs the air around it. This makes changes in air pressure.

Download Presentation

CMPS1371 Introduction to Computing for Engineers

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Processing sounds

PROCESSING SOUNDS

CMPS1371Introduction to Computing for Engineers


The physics of sound

The Physics Of Sound

Why do we hear what we hear?

Sound is made when something vibrates.

The vibration disturbs the air around it.

This makes changes in air pressure.

These changes in air pressure move through the air as sound waves.


Sound volume

Sound Volume

The louder a sound, the more energy it has. This means loud sounds have a large amplitude.

Think about what an amplifier does: it makes sounds louder. It is the amplitude that relates to how loud sound is.


Sound pitch

Sound Pitch

All sound is made by things vibrating. The faster things vibrate, the higher the pitch of the sound produced.

The vibrations being more frequent mean the frequency of the wave increases.


Intensity levels

Intensity Levels


Sound recording and playback

Sound Recording and Playback

Methods to store and reproduce sound is a continual process for high quality

Phonograph

Magnetic tape

Digital recording


Record

Record

  • A sound will be collected as a vector

  • The vector will provide signals over time to represent the frequency (pitch) and amplitude (intensity)


Sound function

Sound Function

  • SOUND function will play the vector as sound.

    • sound(y,Fs) sends the signal in vector Y (with sample frequency FS) out to the speaker on platforms that support sound.

    • sound(y) plays the sound at the default sample rate of 8192 Hz.

    • sound(y,Fs,bits) plays the sound using BITS bits/sample if possible. Most platforms support BITS=8 or 16.

      Example:

      load laughter

      sound(y,Fs)

      plot(y)


Read and write sound files

Read and Write Sound Files

  • y = wavread(FILE)

    • reads a wave file specified by the string FILE, returning the sampled data in y

  • wavwrite(y,Fs,NBITS,WAVEFILE)

    • writes data Y to a Windows WAVE file specified by the file name WAVEFILE, with a sample rate of FS Hz and with NBITS number of bits (default Fs = 8000 hz, NBITS = 16 bits)

  • For audio files use:

    • auread

    • auwrite


Making music with matlab

Making Music with MATLAB

Before we actually start making music, let's revise a few AC waveform basics. Consider the sine wave shown in the figure below:

  • The sine wave shown here can be described mathematically as:

    • v = A sin(2π f t)

  • where A is the Amplitude (varying units), f is the frequency (Hertz) and t is the time (seconds).

  • T is known as the time period (seconds) and T=1/f


  • Music

    Music

    Sound waves are created when a waveform is used to vibrate molecules in a material medium at audio frequencies (300 Hz <= f <= 3 kHz).

    Example:

    the MATLAB code to create a sine wave of amplitude A = 1, at audio frequency of 466.16 Hz (corresponds to A#) would be:

    >> v = sin(2*pi*466.16*[0:0.00125:1.0]);


    Cmps1371 introduction to computing for engineers

    Now, we can either plot this sine wave; or we can hear it!!!

    To plot, simply type:

    >> plot(v);

    Music


    Music1

    Music

    • To hear v, we need to convert the data to some standard audio format

    • Matlab provides a function called wavwrite to convert a vector into wav format and save it on disk.

    • >> wavwrite(v, 'asharp.wav');

    • you can give any file name


    Music2

    Music

    Now, we can "play" this wav file called asharp.wav using any multimedia player.

    wavfunction returns 3 variables:

    Vector signal

    Sampling frequency

    Number of bits

    >> [y, Fs, bits] = wavread('asharp.wav');

    >> sound(y, Fs)


    Music3

    Music

    Now that we can make a single note, we can put notes together and make music!!!

    Let's look at the following piece of music:

    A AE E F# F# E E

    D DC#C# B B A A

    E E D D C# C# B B (repeat once)

    (repeat first two lines once)


    Music4

    Music

    The American Standard Pitch for each of these notes is:

    A: 440.00 Hz

    B: 493.88 Hz

    C#: 554.37 Hz

    D: 587.33 Hz

    E: 659.26 Hz

    F#: 739.99 Hz


    Music5

    Music

    clear;

    a=sin(2*pi*440*(0:0.000125:0.5));

    b=sin(2*pi*493.88*(0:0.000125:0.5));

    cs=sin(2*pi*554.37*(0:0.000125:0.5));

    d=sin(2*pi*587.33*(0:0.000125:0.5));

    e=sin(2*pi*659.26*(0:0.000125:0.5));

    fs=sin(2*pi*739.99*(0:0.000125:0.5));

    line1=[a,a,e,e,fs,fs,e,e,];

    line2=[d,d,cs,cs,b,b,a,a,];

    line3=[e,e,d,d,cs,cs,b,b];

    song=[line1,line2,line3,line3,line1,line2];

    wavwrite(song,'song.wav');


    Sound

    Sound

    SOUND:

    One dimensional function of changing air-pressure in time

    Pressure

    Pressure

    Time t

    Time t


    Sound1

    Sound

    If the function is periodic, we perceive it as sound with a certain frequency (else it’s noise).

    The frequency defines the pitch.

    Pressure

    Pressure

    Time t

    Time t


    Sound2

    Sound

    The SHAPE of the curve defines the sound character

    String

    Flute

    Flute

    String

    Flute

    Flute

    Brass

    Brass


    Sound3

    Sound

    Listening to an orchestra, you can distinguish between different instruments, although the sound is a

    SINGLE FUNCTION !

    Flute

    Brass

    String


    Sound4

    Sound

    If the sound produced by an orchestra is the sum of different instruments, could it be possible that there are BASIC SOUNDS, that can be combined to produce every single sound ?


    Sound5

    Sound

    The answer (Charles Fourier, 1822):

    Any function that periodically repeats itself can be expressed as the sum of sines/cosines of different frequencies, each multiplied by a different coefficient


    Fourier

    Fourier

    …A function…can be expressed as the sum of sines/cosines…

    What happens if we add sine and cosine ?

    a * sin(ωt) + b * cos(ωt)

    = A * sin(ωt + φ)

    Adding sine and cosine of the same frequency yields just another sine function with different phase and amplitude, but same frequency.


    Cmps1371 introduction to computing for engineers

    Any function that periodically repeats itself…

    To change the shape of the function, we must add sine-like functions with different frequencies.

    As a formula:

    f(x)= a0/2 + Σk=1..n akcos(kx) + bksin(kx)

    Fourier

    Fourier Coefficients


    Fourier1

    Fourier

    • The set of ak, bk TOTALLY defines the CURVE synthesized !

    • We can therefore describe the SHAPE of the curve or the CHARACTER of the sound by the (finite ?) set of FOURIER COEFFICIENTS !


    Sawtooth function

    SAWTOOTH Function

    f(x) = ½ - 1/π * Σn 1/n *sin (n*π*x)‏

    Freq

    sin

    cos

    1

    1

    0

    2

    1/2

    0

    3

    1/3

    0

    4

    1/4

    0


    The problem

    The Problem

    Given an arbitrary but periodically one dimensional function (e.g. a sound), can you tell the FOURIER COEFFICIENTS to construct it ?

    The answer (Charles Fourier):

    Yes


    Fast fourier transform

    Fast Fourier Transform

    MATLAB - function fft:

    Input: A vector, representing the discrete function

    Output: The Fourier Coefficients as vector of scaled imaginary numbers

    We can analyze the frequency content of sound using the Fast Fourier Transform (fft)‏


    Fast fourier transform1

    Fast Fourier Transform

    • "Fourier transform" goes from time domain to the frequency domain

    • Decompose a signal into it's sinusoids


    Functionality of the fft

    Functionality of the fft


    Examples

    Examples


  • Login