SlideShare une entreprise Scribd logo
1  sur  14
Sound in Matlab & Cogent
Tobias Overath
Sound
• sound = pressure wave
)2sin()( φπ +⋅⋅⋅= tfAty
Overview
• play sound in Matlab/Cogent
• create a sound
• things you can do with sound:
– louder/quieter
– higher/lower
– combine sounds
• compose & play a melody
Playing a sound in Matlab
• load wavfile
– y = wavread(‘filename.wav’);
• play wavfile
– sound(y,Fs)
• if unsure which Fs
– [y, Fs, nbits, opts] = wavread(‘filename.wav’)
• write to disk
– wavwrite(y,Fs,’filename.wav’)
Playing a sound in Cogent
• config_sound(nchannels,nbits,Fs,nbuffs)
– nchannels: 1 = mono, 2 = stereo
– nbits: e.g. 16
– Fs: sampling frequency (e.g. 44100)
– nbuffs: number of buffers
• wavfilename = [‘filename.wav’];
• loadsound(wavfilename, buffer number)
• playsound(buffer number)
• waitsound(buffer number)
– otherwise next command will be executed
immediately)
creating a sound in Matlab
• Fs = 44100;
• t = [0:1/Fs:1-1/Fs]; %1 second, length 44100
• freq = 400; % Hz
• f1 = sin(2*pi*freq*t);
– sound(f1,Fs)
• f2 = sin(2*pi*(2*freq)*t);
– sound(f2,Fs)
• period: 1/freq (*Fs)
• figure(1);plot(f1)
• figure(2);plot(f1(1:round(1/freq*Fs+1)))
• play consecutively
– f12 = [f1 f2];
– sound(f12,Fs)
• play together/superimposed:
– f_12 = [f1+f2];
• or:
– f_12 = sum([f1;f2]);
– sound(f_12,Fs);
making a sound louder/quieter
• f = sin(2*pi*freq*t)
– standardise sound
• f = f-mean(f);
• f = f/std(f);
• scale sound
– amplitude = .2;
– f = amplitude * f;
• 10^±0.5 for every 10dB
– e.g. 10^1.0  20 dB louder
– e.g. 10^-1.5  30 dB quieter
• do not be put off by warning ‘data clipped’ message. Wavwrite
needs an input vector in the range –1 to +1, else it will clip. The
warning means that you have sounds that are 1 or –1 but the
clipping will leave them unaltered
create noise
• y = .2*randn(1,Fs);
• sound(y,Fs)
FM sweep
• f = chirp(t1,f1,t2,f2);
– t1 = vector t = [0:1/Fs:1-1/fs];
– f1 = initial frequency
– f2 = final frequency
– t2 = time at which f2 is reached
• f = chirp(t,freq,1,2*freq);
• sound(f,Fs)
AM sound
• freq = 400; % carrier frequency
• fm = 10; % modulation frequency
• f_c = sin(2*pi*freq*t);
• f_m = sin(2*pi*fm*t);
• f_mod = [f_c .* f_m];
• sound(f_mod,Fs)
square wave
• x = square(t,duty cycle)
– duty cycle = % of signal that’s positive
• freq = 10;
• fsq = square(2*pi*freq*t);
• fsq = square(2*pi*freq*t, 80);
plot signal
• plot(t,f)
scale
• 12-split equitempered octave
– f(n) = sin(2*pi*freq*2^(n/12)*t)
– for example
n=[0:12]; % 12 semitones
for i=1:length(n)
f(i,:) = sin(2*pi*freq*2^(n(i)/12)*t);
end
fs=[];
for i=1:13
fs = [fs f(i,:)];
end
fs=fs-mean(fs);
fs=fs/std(fs);
fs=.2*fs;
sound(fs,Fs)

Contenu connexe

Tendances

Digital Signal Processing in Hadoop
Digital Signal Processing in HadoopDigital Signal Processing in Hadoop
Digital Signal Processing in HadoopAdam Laiacano
 
Natural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usageNatural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usagehyunyoung Lee
 
A Simple Communication System Design Lab #4 with MATLAB Simulink
A Simple Communication System Design Lab #4 with MATLAB SimulinkA Simple Communication System Design Lab #4 with MATLAB Simulink
A Simple Communication System Design Lab #4 with MATLAB SimulinkJaewook. Kang
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2Oswald Campesato
 
Statistical inference for (Python) Data Analysis. An introduction.
Statistical inference for (Python) Data Analysis. An introduction.Statistical inference for (Python) Data Analysis. An introduction.
Statistical inference for (Python) Data Analysis. An introduction.Piotr Milanowski
 
3 instantiating an object in c# (1)
3  instantiating an object in c# (1)3  instantiating an object in c# (1)
3 instantiating an object in c# (1)abdullah619
 
A Simple Communication System Design Lab #3 with MATLAB Simulink
A Simple Communication System Design Lab #3 with MATLAB SimulinkA Simple Communication System Design Lab #3 with MATLAB Simulink
A Simple Communication System Design Lab #3 with MATLAB SimulinkJaewook. Kang
 
Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Databricks
 
TensorFlow example for AI Ukraine2016
TensorFlow example  for AI Ukraine2016TensorFlow example  for AI Ukraine2016
TensorFlow example for AI Ukraine2016Andrii Babii
 
機械学習によるデータ分析 実践編
機械学習によるデータ分析 実践編機械学習によるデータ分析 実践編
機械学習によるデータ分析 実践編Ryota Kamoshida
 
Dsp gcu lab11
Dsp gcu lab11Dsp gcu lab11
Dsp gcu lab11Jannat41
 
The Joy of SciPy
The Joy of SciPyThe Joy of SciPy
The Joy of SciPykammeyer
 
Introduction to TensorFlow, by Machine Learning at Berkeley
Introduction to TensorFlow, by Machine Learning at BerkeleyIntroduction to TensorFlow, by Machine Learning at Berkeley
Introduction to TensorFlow, by Machine Learning at BerkeleyTed Xiao
 
Project session part_I
Project  session part_IProject  session part_I
Project session part_IMina Yonan
 
Machine Learning - Introduction to Tensorflow
Machine Learning - Introduction to TensorflowMachine Learning - Introduction to Tensorflow
Machine Learning - Introduction to TensorflowAndrew Ferlitsch
 

Tendances (20)

Digital Signal Processing in Hadoop
Digital Signal Processing in HadoopDigital Signal Processing in Hadoop
Digital Signal Processing in Hadoop
 
Natural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usageNatural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usage
 
H2 o berkeleydltf
H2 o berkeleydltfH2 o berkeleydltf
H2 o berkeleydltf
 
A Simple Communication System Design Lab #4 with MATLAB Simulink
A Simple Communication System Design Lab #4 with MATLAB SimulinkA Simple Communication System Design Lab #4 with MATLAB Simulink
A Simple Communication System Design Lab #4 with MATLAB Simulink
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2
 
Statistical inference for (Python) Data Analysis. An introduction.
Statistical inference for (Python) Data Analysis. An introduction.Statistical inference for (Python) Data Analysis. An introduction.
Statistical inference for (Python) Data Analysis. An introduction.
 
Fourier image
Fourier imageFourier image
Fourier image
 
3 instantiating an object in c# (1)
3  instantiating an object in c# (1)3  instantiating an object in c# (1)
3 instantiating an object in c# (1)
 
A Simple Communication System Design Lab #3 with MATLAB Simulink
A Simple Communication System Design Lab #3 with MATLAB SimulinkA Simple Communication System Design Lab #3 with MATLAB Simulink
A Simple Communication System Design Lab #3 with MATLAB Simulink
 
Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0
 
About RNN
About RNNAbout RNN
About RNN
 
About RNN
About RNNAbout RNN
About RNN
 
TensorFlow example for AI Ukraine2016
TensorFlow example  for AI Ukraine2016TensorFlow example  for AI Ukraine2016
TensorFlow example for AI Ukraine2016
 
機械学習によるデータ分析 実践編
機械学習によるデータ分析 実践編機械学習によるデータ分析 実践編
機械学習によるデータ分析 実践編
 
Dsp gcu lab11
Dsp gcu lab11Dsp gcu lab11
Dsp gcu lab11
 
The Joy of SciPy
The Joy of SciPyThe Joy of SciPy
The Joy of SciPy
 
Music as data
Music as dataMusic as data
Music as data
 
Introduction to TensorFlow, by Machine Learning at Berkeley
Introduction to TensorFlow, by Machine Learning at BerkeleyIntroduction to TensorFlow, by Machine Learning at Berkeley
Introduction to TensorFlow, by Machine Learning at Berkeley
 
Project session part_I
Project  session part_IProject  session part_I
Project session part_I
 
Machine Learning - Introduction to Tensorflow
Machine Learning - Introduction to TensorflowMachine Learning - Introduction to Tensorflow
Machine Learning - Introduction to Tensorflow
 

Similaire à Sound Analysis and Synthesis in Matlab and Cogent

It's so quiet. Let's make music.
It's so quiet. Let's make music.It's so quiet. Let's make music.
It's so quiet. Let's make music.Loren Segal
 
orfanidis-solutions-book-2nd-edition-pdf
orfanidis-solutions-book-2nd-edition-pdforfanidis-solutions-book-2nd-edition-pdf
orfanidis-solutions-book-2nd-edition-pdfmavim69186
 
Introduction to Signal Processing Orfanidis [Solution Manual]
Introduction to Signal Processing Orfanidis [Solution Manual]Introduction to Signal Processing Orfanidis [Solution Manual]
Introduction to Signal Processing Orfanidis [Solution Manual]slyhamm
 
Lectures on digital communication by prof.dr.a.abbas
Lectures on digital communication by prof.dr.a.abbasLectures on digital communication by prof.dr.a.abbas
Lectures on digital communication by prof.dr.a.abbasProfArshadAbbas
 
Lectures on Digital Dommunication by Prof.Dr.A.Abbas Khan
Lectures on Digital Dommunication by Prof.Dr.A.Abbas KhanLectures on Digital Dommunication by Prof.Dr.A.Abbas Khan
Lectures on Digital Dommunication by Prof.Dr.A.Abbas KhanProfArshadAbbas
 
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio filesMinh Anh Nguyen
 
NoiseGen at Arlington Ruby 2012
NoiseGen at Arlington Ruby 2012NoiseGen at Arlington Ruby 2012
NoiseGen at Arlington Ruby 2012awwaiid
 
12 Narrow_band_and_Wide_band_FM.pdf
12 Narrow_band_and_Wide_band_FM.pdf12 Narrow_band_and_Wide_band_FM.pdf
12 Narrow_band_and_Wide_band_FM.pdfMohamedshabana38
 
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio filesMinh Anh Nguyen
 
Digital signal processing through speech, hearing, and Python
Digital signal processing through speech, hearing, and PythonDigital signal processing through speech, hearing, and Python
Digital signal processing through speech, hearing, and PythonMel Chua
 
Lecture 09 interference for sound waves. beats. doppler effect
Lecture 09   interference for sound waves. beats. doppler effectLecture 09   interference for sound waves. beats. doppler effect
Lecture 09 interference for sound waves. beats. doppler effectAlbania Energy Association
 

Similaire à Sound Analysis and Synthesis in Matlab and Cogent (18)

It's so quiet. Let's make music.
It's so quiet. Let's make music.It's so quiet. Let's make music.
It's so quiet. Let's make music.
 
lec-4.ppt
lec-4.pptlec-4.ppt
lec-4.ppt
 
lec-4.ppt
lec-4.pptlec-4.ppt
lec-4.ppt
 
lec-4.ppt
lec-4.pptlec-4.ppt
lec-4.ppt
 
orfanidis-solutions-book-2nd-edition-pdf
orfanidis-solutions-book-2nd-edition-pdforfanidis-solutions-book-2nd-edition-pdf
orfanidis-solutions-book-2nd-edition-pdf
 
Introduction to Signal Processing Orfanidis [Solution Manual]
Introduction to Signal Processing Orfanidis [Solution Manual]Introduction to Signal Processing Orfanidis [Solution Manual]
Introduction to Signal Processing Orfanidis [Solution Manual]
 
Lectures on digital communication by prof.dr.a.abbas
Lectures on digital communication by prof.dr.a.abbasLectures on digital communication by prof.dr.a.abbas
Lectures on digital communication by prof.dr.a.abbas
 
Lectures on Digital Dommunication by Prof.Dr.A.Abbas Khan
Lectures on Digital Dommunication by Prof.Dr.A.Abbas KhanLectures on Digital Dommunication by Prof.Dr.A.Abbas Khan
Lectures on Digital Dommunication by Prof.Dr.A.Abbas Khan
 
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio files
 
NoiseGen at Arlington Ruby 2012
NoiseGen at Arlington Ruby 2012NoiseGen at Arlington Ruby 2012
NoiseGen at Arlington Ruby 2012
 
12 Narrow_band_and_Wide_band_FM.pdf
12 Narrow_band_and_Wide_band_FM.pdf12 Narrow_band_and_Wide_band_FM.pdf
12 Narrow_band_and_Wide_band_FM.pdf
 
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio files
 
Digital signal processing through speech, hearing, and Python
Digital signal processing through speech, hearing, and PythonDigital signal processing through speech, hearing, and Python
Digital signal processing through speech, hearing, and Python
 
Lab Activity
Lab ActivityLab Activity
Lab Activity
 
Lecture 09 interference for sound waves. beats. doppler effect
Lecture 09   interference for sound waves. beats. doppler effectLecture 09   interference for sound waves. beats. doppler effect
Lecture 09 interference for sound waves. beats. doppler effect
 
Lecture22
Lecture22Lecture22
Lecture22
 
Lecture22
Lecture22Lecture22
Lecture22
 
Polyanna manual
Polyanna manualPolyanna manual
Polyanna manual
 

Plus de umarjamil10000

Plus de umarjamil10000 (8)

Galvanometer,wheatstone bridge,ohm law,
Galvanometer,wheatstone bridge,ohm  law,Galvanometer,wheatstone bridge,ohm  law,
Galvanometer,wheatstone bridge,ohm law,
 
Mechatronics, Embedded System,
Mechatronics, Embedded System,Mechatronics, Embedded System,
Mechatronics, Embedded System,
 
Electric Field
Electric FieldElectric Field
Electric Field
 
Image denoising
Image denoising Image denoising
Image denoising
 
Coding verilog
Coding verilogCoding verilog
Coding verilog
 
Matlab dsp examples
Matlab dsp examplesMatlab dsp examples
Matlab dsp examples
 
Pm project
Pm projectPm project
Pm project
 
Mechatronics systems
Mechatronics systemsMechatronics systems
Mechatronics systems
 

Dernier

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 

Dernier (20)

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 

Sound Analysis and Synthesis in Matlab and Cogent

  • 1. Sound in Matlab & Cogent Tobias Overath
  • 2. Sound • sound = pressure wave )2sin()( φπ +⋅⋅⋅= tfAty
  • 3. Overview • play sound in Matlab/Cogent • create a sound • things you can do with sound: – louder/quieter – higher/lower – combine sounds • compose & play a melody
  • 4. Playing a sound in Matlab • load wavfile – y = wavread(‘filename.wav’); • play wavfile – sound(y,Fs) • if unsure which Fs – [y, Fs, nbits, opts] = wavread(‘filename.wav’) • write to disk – wavwrite(y,Fs,’filename.wav’)
  • 5. Playing a sound in Cogent • config_sound(nchannels,nbits,Fs,nbuffs) – nchannels: 1 = mono, 2 = stereo – nbits: e.g. 16 – Fs: sampling frequency (e.g. 44100) – nbuffs: number of buffers • wavfilename = [‘filename.wav’]; • loadsound(wavfilename, buffer number) • playsound(buffer number) • waitsound(buffer number) – otherwise next command will be executed immediately)
  • 6. creating a sound in Matlab • Fs = 44100; • t = [0:1/Fs:1-1/Fs]; %1 second, length 44100 • freq = 400; % Hz • f1 = sin(2*pi*freq*t); – sound(f1,Fs) • f2 = sin(2*pi*(2*freq)*t); – sound(f2,Fs) • period: 1/freq (*Fs) • figure(1);plot(f1) • figure(2);plot(f1(1:round(1/freq*Fs+1)))
  • 7. • play consecutively – f12 = [f1 f2]; – sound(f12,Fs) • play together/superimposed: – f_12 = [f1+f2]; • or: – f_12 = sum([f1;f2]); – sound(f_12,Fs);
  • 8. making a sound louder/quieter • f = sin(2*pi*freq*t) – standardise sound • f = f-mean(f); • f = f/std(f); • scale sound – amplitude = .2; – f = amplitude * f; • 10^±0.5 for every 10dB – e.g. 10^1.0  20 dB louder – e.g. 10^-1.5  30 dB quieter • do not be put off by warning ‘data clipped’ message. Wavwrite needs an input vector in the range –1 to +1, else it will clip. The warning means that you have sounds that are 1 or –1 but the clipping will leave them unaltered
  • 9. create noise • y = .2*randn(1,Fs); • sound(y,Fs)
  • 10. FM sweep • f = chirp(t1,f1,t2,f2); – t1 = vector t = [0:1/Fs:1-1/fs]; – f1 = initial frequency – f2 = final frequency – t2 = time at which f2 is reached • f = chirp(t,freq,1,2*freq); • sound(f,Fs)
  • 11. AM sound • freq = 400; % carrier frequency • fm = 10; % modulation frequency • f_c = sin(2*pi*freq*t); • f_m = sin(2*pi*fm*t); • f_mod = [f_c .* f_m]; • sound(f_mod,Fs)
  • 12. square wave • x = square(t,duty cycle) – duty cycle = % of signal that’s positive • freq = 10; • fsq = square(2*pi*freq*t); • fsq = square(2*pi*freq*t, 80);
  • 14. scale • 12-split equitempered octave – f(n) = sin(2*pi*freq*2^(n/12)*t) – for example n=[0:12]; % 12 semitones for i=1:length(n) f(i,:) = sin(2*pi*freq*2^(n(i)/12)*t); end fs=[]; for i=1:13 fs = [fs f(i,:)]; end fs=fs-mean(fs); fs=fs/std(fs); fs=.2*fs; sound(fs,Fs)