Digital Signalbehandling i Audio/Video

Similar documents
DSP First. Laboratory Exercise #4. AM and FM Sinusoidal Signals

CMPT 468: Frequency Modulation (FM) Synthesis

Linear Frequency Modulation (FM) Chirp Signal. Chirp Signal cont. CMPT 468: Lecture 7 Frequency Modulation (FM) Synthesis

Spectrum. Additive Synthesis. Additive Synthesis Caveat. Music 270a: Modulation

Music 270a: Modulation

Lab 4 Fourier Series and the Gibbs Phenomenon

CS 591 S1 Midterm Exam

ECE 201: Introduction to Signal Analysis

The Formula for Sinusoidal Signals

Communication Engineering Prof. Surendra Prasad Department of Electrical Engineering Indian Institute of Technology, Delhi

Fourier Series and Gibbs Phenomenon

Music 171: Amplitude Modulation

School of Engineering and Information Technology ASSESSMENT COVER SHEET

DSP First Lab 03: AM and FM Sinusoidal Signals. We have spent a lot of time learning about the properties of sinusoidal waveforms of the form: k=1

DSP First Lab 05: FM Synthesis for Musical Instruments - Bells and Clarinets

DSP First. Laboratory Exercise #7. Everyday Sinusoidal Signals

Combining granular synthesis with frequency modulation.

Lab10: FM Spectra and VCO

Problem Set 8 #4 Solution

Computer Music in Undergraduate Digital Signal Processing

DSP First. Laboratory Exercise #2. Introduction to Complex Exponentials

Lab P-4: AM and FM Sinusoidal Signals. We have spent a lot of time learning about the properties of sinusoidal waveforms of the form: ) X

SuperCollider Tutorial

Problem Set 1 (Solutions are due Mon )

What is Sound? Simple Harmonic Motion -- a Pendulum

CMPT 368: Lecture 4 Amplitude Modulation (AM) Synthesis

Sound synthesis with Pure Data

Additive Synthesis OBJECTIVES BACKGROUND

INTRODUCTION TO COMPUTER MUSIC. Roger B. Dannenberg Professor of Computer Science, Art, and Music. Copyright by Roger B.

Professorial Inaugural Lecture, 26 April 2001 DIGITAL SYNTHESIS OF MUSICAL SOUNDS. B.T.G. Tan Department of Physics National University of Singapore

Synthesis: From Frequency to Time-Domain

Alternative View of Frequency Modulation

Fall Music 320A Homework #2 Sinusoids, Complex Sinusoids 145 points Theory and Lab Problems Due Thursday 10/11/2018 before class

Lab S-8: Spectrograms: Harmonic Lines & Chirp Aliasing

George Mason University Signals and Systems I Spring 2016

Massachusetts Institute of Technology Dept. of Electrical Engineering and Computer Science Fall Semester, Introduction to EECS 2

Outline. Communications Engineering 1

Part-I. Experiment 6:-Angle Modulation

Sound Synthesis. A review of some techniques. Synthesis

A-110 VCO. 1. Introduction. doepfer System A VCO A-110. Module A-110 (VCO) is a voltage-controlled oscillator.

Solution to Chapter 4 Problems

Digital Signal Processing Lecture 1 - Introduction

Developing a Versatile Audio Synthesizer TJHSST Senior Research Project Computer Systems Lab

Sound Synthesis Methods

What is Sound? Part II

Waveshaping Synthesis. Indexing. Waveshaper. CMPT 468: Waveshaping Synthesis

Audio Engineering Society Convention Paper Presented at the 110th Convention 2001 May Amsterdam, The Netherlands

PHY-2464 Physical Basis of Music

Lab 9 Fourier Synthesis and Analysis

ELT COMMUNICATION THEORY

Lab 1: Analog Modulations

P. Moog Synthesizer I

Music 171: Sinusoids. Tamara Smyth, Department of Music, University of California, San Diego (UCSD) January 10, 2019

THE STATE UNIVERSITY OF NEW JERSEY RUTGERS. College of Engineering Department of Electrical and Computer Engineering

NEGATIVE FREQUENCIES AND THROUGH-ZERO FREQUENCY MODULATION

ECE 201: Introduction to Signal Analysis. Dr. B.-P. Paris Dept. Electrical and Comp. Engineering George Mason University

Oscillations II: Damped and/or Driven Oscillations

ECE 201: Introduction to Signal Analysis

Lecture 7 Frequency Modulation

GEORGIA INSTITUTE OF TECHNOLOGY. SCHOOL of ELECTRICAL and COMPUTER ENGINEERING

Computer Audio. An Overview. (Material freely adapted from sources far too numerous to mention )

Angle Modulated Systems

Lab 3 SPECTRUM ANALYSIS OF THE PERIODIC RECTANGULAR AND TRIANGULAR SIGNALS 3.A. OBJECTIVES 3.B. THEORY

Interpolation Error in Waveform Table Lookup

Implementing whistler sound by using sound synthesis. Physics 406 Oral Presentation Project. Dongryul Lee

4.1 REPRESENTATION OF FM AND PM SIGNALS An angle-modulated signal generally can be written as

Subtractive Synthesis. Describing a Filter. Filters. CMPT 468: Subtractive Synthesis

Laboratory Assignment 2 Signal Sampling, Manipulation, and Playback

Signals and Systems Lecture 9 Communication Systems Frequency-Division Multiplexing and Frequency Modulation (FM)

ELE636 Communication Systems

Figure 1: Block diagram of Digital signal processing

Signal Processing. Introduction

VIBRATO DETECTING ALGORITHM IN REAL TIME. Minhao Zhang, Xinzhao Liu. University of Rochester Department of Electrical and Computer Engineering

Synthesis Techniques. Juan P Bello

EECE 323 Fundamentals of Digital Signal Processing. Spring Section A. Practical Homework MATLAB Application on Aliasing and Antialiasing

Here are some of Matlab s complex number operators: conj Complex conjugate abs Magnitude. Angle (or phase) in radians

Sound is the human ear s perceived effect of pressure changes in the ambient air. Sound can be modeled as a function of time.

Chapter 5: Music Synthesis Technologies

1B Paper 6: Communications Handout 2: Analogue Modulation

Discrete Fourier Transform

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering. EIE2106 Signal and System Analysis Lab 2 Fourier series

YAMAHA. Modifying Preset Voices. IlU FD/D SUPPLEMENTAL BOOKLET DIGITAL PROGRAMMABLE ALGORITHM SYNTHESIZER

Signal Processing First Lab 02: Introduction to Complex Exponentials Multipath. x(t) = A cos(ωt + φ) = Re{Ae jφ e jωt }

Complex Sounds. Reading: Yost Ch. 4

Musical Acoustics, C. Bertulani. Musical Acoustics. Lecture 14 Timbre / Tone quality II

Phase demodulation using the Hilbert transform in the frequency domain

FIR/Convolution. Visulalizing the convolution sum. Convolution

EECS 216 Winter 2008 Lab 2: FM Detector Part I: Intro & Pre-lab Assignment

How to Graph Trigonometric Functions

Digital Signal Processing PW1 Signals, Correlation functions and Spectra

Lab S-7: Spectrograms of AM and FM Signals. 2. Study the frequency resolution of the spectrogram for two closely spaced sinusoids.

Math and Music: Understanding Pitch

1 Introduction and Overview

ANALOGUE TRANSMISSION OVER FADING CHANNELS

Complex Numbers in Electronics


CS 591 S1 Midterm Exam Solution

Synthesizer. Team Members- Abhinav Prakash Avinash Prem Kumar Koyya Neeraj Kulkarni

Modulation is the process of impressing a low-frequency information signal (baseband signal) onto a higher frequency carrier signal

UNIT-2 Angle Modulation System

Transcription:

Digital Signalbehandling i Audio/Video Institutionen för Elektrovetenskap Computer exercise 4 in english Martin Stridh Lund 2006

2

Innehåll 1 Datorövningar 5 1.1 Exercises for exercise 12/Computer exercise 4: sound synthesis........ 5 1.1.1 Preparations................................ 5 1.1.2 FM synthesis................................ 5 1.1.3 Exercises.................................. 7 2 Solution till computer exercise 13 2.1 Solution till computer exercise 4......................... 13 3

4 INNEHÅLL

Kapitel 1 Datorövningar 1.1 Exercises for exercise 12/Computer exercise 4: sound synthesis This exercise is to synthesize different sounds in MATLAB. There are today many ways to synthesize the sound in a computer. The method we will look at is the FM synthesis, where FM stands for frequency modulation. This is the same method used to transfer radio signals. FM synthesis was long the dominant form of sound synthesis and used in Yamahas enormously popular synth DX-7 and also in the first sound cards for PCs. However today another method is dominating namely the so-called wave table synthesis. The wave table synthesis uses a wave table with sampled (recorded) tones. These tones are then combined and modified by the signal to get the desired effect. For instance, Wave Table Synthesis is used to create the polyphonic ring tones in mobile phones. FM synthesis and wave table synthesis is not the only synthesis methods. The analog synthesizers frequently used subtractive synthesis. As the computers become faster, interest in methods based on physical modeling of the instruments has increased. Methods based on wavelet theory has received increased attention in recent years. Perhaps that this is the future of computerized music, who knows? 1.1.1 Preparations Read section 1.1.2 Read section 1.1.3 1.1.2 FM synthesis That frequency modulation could be used to synthesize the sound was discovered by a gentleman named John Chowning. This happened one evening in 1967 when Chowning played with some oscillators to explore the effects of vibrato. He did this by allowing the output signal from an oscillator to control another. Vibrato are small variations in the pitch of a sound. In audio synthesis, vibrato is often added to the sound to make it more realistic. This is done by allowing an oscillator modulate the frequency of another. In order to create vibrato, the modulating frequency to be below the hearing threshold, ie < 20 Hz. What Chowning did was that he increased the frequency of the modulating signal to about 20 Hz. What happened was that, instead of being a variation in frequency between the pure tones in the modulated signal, created a sound that had several harmonics. Chowning thought that this effect was interesting and began to explore the potential of their discovery. The result was that he soon had synthesized a number of sounds including different bell-like sounds 5

6 KAPITEL 1. DATORÖVNINGAR and the clarinet-like sound. His experiments resulted in an article published in Journal of the Audio Engineering Society. Even today is Chownings Article considered as a reference in FM synthesis. Yamaha eventually wrote a contract with Chowning to have exclusive rights to his discovery. It took seven years to bring down the algorithm on a chip that could be used for commercial purposes. However, it was worth it for 1983 Yamaha launched its DX-7 synthesizer. The today, best-selling synthesizer in the world. The theory behind FM synthesis is quite simple, at least for the case of only two oscillators. It is this case we will look at. An FM signal is as follows x(t) = A cos(φ(t)) where the instantaneous frequency of cosine function is given by d dtφ(t). By letting Φ(t) be an appropriate function, different effects may be obtained. In this exercise Φ(t) will be a cosine function. The instantaneous frequency of x(t) will then vary according to d dt Φ(t) = d dt cos(t) = sin(t), i.e. sinusoidal. A more general formula for an FM synthesizer is as follows: x(t) = A(t) cos(2πf c t + I(t) cos(2πf m t + ϕ m ) + ϕ c ) (1.1) What are the parameters in the equation (1.1)? We start with A(t) which is the amplitude of the signal which is time-dependent. A(t) is what is usually called a envelope. The word envelope is borrowed from the English envelope which means cover or containment which is a pretty good description of what an envelope does. The following example is intended to demonstrate the effect of multiplying a signal with an envelope. Suppose that our signal is x(t) = cos(t) and that our envelope is given by A(t) = e t. Figure 1.1 shows the cosine 1 0.5 0 0.5 1 0 1 2 3 4 5 6 7 8 9 x 10 4 1 0.5 0 0 1 2 3 4 5 6 7 8 9 x 10 4 1 0.5 0 0.5 1 0 1 2 3 4 5 6 7 8 9 x 10 4 Figur 1.1: on top a cosine function, x(t), in the middle an envelope, A(t) = e t and at the bottom x(t) A(t) (solid line) and A(t) (dashed line) function, the envelope and the result of the multiplication. A(t) gives us an opportunity to shape the signal amplitude. In the example above, the signal is slowly decaying. Exponential envelope is used to synthesize the sound of a bell as we shall see later. The frequency f c is called the carrier frequency. It is the frequency the signal would have had in case there was no modulation, ie if Φ(t) has been constant. The frequency f m is the so-called modulation frequency. This frequency determines how rapidly the instantaneous frequency of the signal oscillate. ϕ c and ϕ m are arbitrary constants. They are often set to π/2 so that x(0) = 0. I(t) is also an envelope. It is customary to call I(t) for a modulation index. It is not clear what the I(t) does with the signal and what impact it will have on the sound that x(t) generates. In equation (1.1), we see that I(t) is the amplitude envelope for modulating the cosine signal. This means that I(t) will determine how much the signal s instantaneous frequency will deviate from the carrier frequency f c. Four parameters are all that is required to generate a variety of sounds with this simple FM synth. That is the great strengths of FM synthesis. Many sounds can be achieved

1.1. EXERCISES FOR EXERCISE 12/COMPUTER EXERCISE 4: SOUND SYNTHESIS7 with few parameters. The disadvantage is it is difficult to get a feel for what happens when the parameters change. There is no intuitive link between the resulting sound and the parameters. When Chowning made his discovery, he noticed that the resulting sound is comprised of many harmonics. What the sound spectrum will look like will be determined by the relationship between carrier frequency (f c ) and modulation frequency (f m ) while the modulation index I(t) determines the number of harmonics and their amplitude. The relationship is usually written as C : M, where C and M are integers, eg 1 : 2, which means that the modulation frequency will be twice as large as the carrier frequency. There are some guidelines for how the signal spectra will be affected by the relationship between carrier and modulation frequency. Firstly, the side-bands will end up at the frequencies f c ± nf m n = 0, 1, 2,... Integer n is called the order of the side band. The spectrum of the signal has side bands on both sides of the carrier frequency and hence the side bands for a specific order is always found in pairs. The side-band ports of negative frequencies is reflected around zero, ie to produce a negative frequency you take the absolute value of the frequency. It can happen that a side band is reflected to a frequency where there is already a positive side-band. The Amplitude of the two side bands will then be added together, the negative frequency will be phase shifted 180 relative to the positive, which means that the amplitude will be inverted. The fundamental frequency is the lowest frequency in the signal spectra. Side bands, which is on a multiple of the fundamental frequency is called the harmonic side bands or overtones. It can also happen that the signal contains side bands which are at frequencies that are not a multiple of the fundamental frequency. These are called non-harmonic side bands. Different kinds drum sounds tend to have a non-harmonic frequency content. the signals fundamental frequency is equal to the carrier frequency f c if and only if f m is at least twice as large as f c. 1.1.3 Exercises Exercise 1: Write a MATLAB function that implements the equation (??). The function will look as follows: function cc = synth(fc, fm, Aenv, Ienv, dur, fs) cc = synth(fc, fm, Aenv, Ienv, dur, fs) Where the input parameters are: Fc = carrier frequency in Hz Fm = modulationfrekvensen in Hz Aenv = is a constant which scales the amplitude Ienv = is a constant which scales the amplitude of the modulating signal Dur = signal duration in seconds Fs = sampling frequency in Hz Note that Aenv and Ienv are so far only constants. Set ϕ c = ϕ m = π 2. Hint: The time array used to create the signal is created by using fs and dur. Exercise 2: Try the synthesizer from exercise 1. Try some different values of f c and f m. Remember that it is the relationship between carrier and modulation frequency which determine what the signal spectra will look like. Try also some different values of Aenv and Ienv. Listen to the result with the command sound in MATLAB.

8 KAPITEL 1. DATORÖVNINGAR sound(cc, fs) Remember to use the same sampling rate as when you created the signal. Plot the signal as a function of time. Plot the spectrum of the signal with the commands: f = ((0:length(cc)-1)/length(cc))*fs; s = abs(fft(cc, length(cc))); s = 20*log10(s); plot(f, s) xlabel( Frekvens (Hz) ); ylabel( Amplitud (db) ) Try some values of f m below the hearing threshold, such as f m = 1Hz, 5Hz, 10Hz. Plot the spectrum of the signal and compare it to how it looked when f m > 20Hz. Plot the signal and compare. Hint: Use : to plot only part of the signal. Eg plot(t(1:200), cc(1:200)) only plots the 200 first sample of cc. Type the code to plot the spectrum in a m-file. This code will be used several times. Exercise 3: We will now start watching the amplitude envelope and the envelope for the modulation index for a bell sound. Envelope is in both cases, exponentially decaying, ie A = A 0 e t/τ resp. I = I 0 e t/τ Where τ is a time constant and A 0 and I 0 are constant scale factors. Write a MATLAB function that generates the two envelopes. The function will look as follows: function [Aenv, Ienv] = bellenv(a0, I0, tau, dur, fs) BELLENV generates the envelope of a bell sound [Aenv, Ienv] = bellenv (A0, I0, tau, dur, fs); input parameters Tau = time constant specified in seconds Dur = envelopes duration in seconds Fs = sampling frequency in Hz Returned: Aenv = exponentially decaying envelope for amplitude Ienv = exponentially decaying envelope for modulation index Choose τ = 2s, A 0 = 1, I 0 = 10, f s = 11,025 Hz. Generate the two envelopes and plot them as a function of time. Hint: The time array used to create the signal is created by using fs and dur. Exercise 4: Before the envelope, which was generated in the previous task, can be used the function synth must be modified slightly. Modify the function synth so that the vectors of any length can be used as envelope, ie so that Aenv and Ienv can be vectors of arbitrary length. Hint: In MATLAB element wise multiplication of two vectors can be done smoothly with the command.* In order to deal with arbitrarily long vectors, compare the length of the input arguments and the length of the time array and take appropriate action if they are not of equal length.

1.1. EXERCISES FOR EXERCISE 12/COMPUTER EXERCISE 4: SOUND SYNTHESIS9 Exercise 5: Now is the time to try the synthesizer with the new envelope. For the bell sounds, it is appropriate to have a relationship between f c and f m at 1:2. Try the different parameter sets below. In all cases, A 0 = 1. Tabell 1.1: Parameter sets for exercise 5 Sets f c (Hz) f m (Hz) I 0 τ (s) dur (s) f s (Hz) 1 110 220 10 2 6 11025 2 220 440 5 2 6 11025 3 110 220 10 12 3 11025 4 110 220 10 0.3 3 11025 5 250 350 5 2 5 11025 6 250 350 3 1 5 11025 For each of the cases above, listen to the sound. Sounds like a bell? Plot the signal and compares with envelope, A(t), generated by bellenv. Plot the signal spectra. This is done with the commands: f = ((0:length(cc)-1)/length(cc))*fs; s = abs(fft(cc, length(cc))); s = 20*log10(s); plot(f, s) xlabel( Frequency (Hz) ); ylabel( Amplitude (db) ) What is the fundamental frequency of the sound? What overtones contains the sound? Plot a number of samples in the middle of the signal and look at how the frequency of the signal changes. Plot the instantaneous frequency as a function of time. This you do with the function instfreq. function instfreq(fc, fm, I0, Ienv, tau, dur, fs) Function calculating the instantaneous power of a bell sound and then plot the instantaneous frequency as a function of time How does the instantaneous frequency change with time? What impact does I(t) have on the instantaneous frequency? Exercise 6: In this task, we shall synthesize the sound of a clarinet. The envelope of a clarinet is different from those we have previously seen for the bell sounds. The envelope of a clarinet has an attack, a sustain and a release part. The attack part is the beginning of a sound. Our view on what kind of instrument the sound is coming from is based mostly on the attack part. After the attack part, the sustain part takes place. During this part the sound is kept at a certain level. When the sustain part is ending the release part starts. It is during this part as the sound starts to decay. Generate the amplitude envelope and envelope for the modulation index of a clarinet. For this you can use the function woodwenv. function [Aenv, Ienv] = woodwenv(att, sus, rel, fs) WOODWENV generates amplitude envelop and envelope for modulation index For woodwind instruments [Aenv, Ienv] = woodwenv (that, sus, rel, fs); Where to = attack time (s) Sus = sustain time (s)

10 KAPITEL 1. DATORÖVNINGAR Rel = release time (s) Fs = sampling frequency (Hz) Returned: Aenv = amplitude envelop Ienv = modulation index envelop NOTE: attack time is exponential, sustain time is constant, Release time is exponential Plot the two envelope with the commands: fs = 8000; tt = 0:1/fs:0.5-1/fs; 0.5 seconds is the duration of the sound [Aenv, Ienv] = woodwenv(0.1, 0.35, 0.05, fs); subplot(211); plot(tt, Aenv); grid on subplot(212); plot(tt, Ienv); grid on Exercise 7: Now synthesize a clarinet sound. The relationship between f c and f m to be 2:3 for a clarinet. The choice of frequencies is up to you. Use the envelope you plotted in the previous exercise. Does that sound like a clarinet? Plot the signal as a function of time: plot(tt, cc). Watch how the A(t) affects the signal. Plot the spectrum of the signal. f = ((0:length(cc)-1)/length(cc))*fs; s = abs(fft(cc, length(cc))); s = 20*log10(s); plot(f, s) xlabel( Frequency (Hz) ); ylabel( Amplitude (db) ) What is the frequency content? What is the fundamental frequency? Plot approximately 200 samples in the middle of the signal and look at how the frequency changes. Try to synthesize different fundamental frequencies. Exercise 8: In exercise 6, we saw that the envelope had an attack- a sustain and a release part. A slightly more general form of the envelope is the so-called ADSR (Attack Decay Sustain Release) envelope. ADSR envelope has a decay part after the attack part. How an ADSR envelope looks can be seen in Figure1.2. 1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 Figur 1.2: An ADSR envelope of a signal of duration 0.6 seconds. During the attack part the function grows linearly up to one. Then the function decreases linearly down to 2/3 during the decay part. During the sustain part the function remains constant on the value 2/3 and then decreases down to zero during the release part Write a function that generates a constant envelope with the appearance of Figure??. The function will look as follows:

1.1. EXERCISES FOR EXERCISE 12/COMPUTER EXERCISE 4: SOUND SYNTHESIS11 function [Aenv, Ienv] = brassenv(att, dec, sus, rel, I0, fs) [Aenv, Ienv] = brassenv (that, in dec, sus, rel, I0, fs) Function that creates an ADSR envelope for amplitude and modulation index NOTE: signal duration dur = to + dec + sus + rel Generare the two envelopes. Let att, dec, rel be equal to 0.1s and sus be equal to 0.3s. Appropriate choice of I 0 is 5. Further let f s be equal to 8000Hz. Exercise 9: Use the envelope from the previous task to synthesize a trumpet sound. To get a good result, f c = f m. Remember to have the same sampling rate as when you created the envelope. Listen to the tone. Does that sound like a trumpet? Plot the signal as a function of time. fs = 8000; tt = 0:1/fs:0.6-1/fs; 0.6 seconds is the duration of the soundplot(tt, cc) How does the amplitude envelope affect the signal? Plot the spectrum of the signal. f = ((0:length(cc)-1)/length(cc))*fs; s = abs(fft(cc, length(cc))); s = 20*log10(s); plot(f, s) xlabel( Frequency (Hz) ); ylabel( Amplitude (db) ) What is the fundamental frequency? What harmonics are present? Plot approximately 200 samples in the middle of the signal and to study the frequency variation. Exercise 10: The function drumenv create an envelope for a simple drum sound (Bongo drum). Create an envelope of a signal which lasts for 0.2 s with a sampling rate of 8000 Hz. function [Aenv, Ienv] = drumenv(dur, fs) Function that generates amplitude envelop and envelope of modulation index for a drum sound Plot the two envelopes as a function of time. tt = 0:1/fs:dur-1/fs; subplot(211); plot(tt, Aenv); axis([0 0.2 0 2]) subplot(212); plot(tt, Ienv) Exercise 11: Use the envelope in the previous exercise, and synthesize a 0.2 s drum sound. Frequencies will be f c = 131 Hz and f m = 0.618 f c. Listen to the result. How does that sound? Plot the signal as a function of time. How does the signal look like? How is it different from the other signals you synthesized? Plot the spectrum of the signal. Is spectrum harmonic? f = ((0:length(cc)-1)/length(cc))*fs; s = abs(fft(cc, length(cc))); s = 20*log10(s); plot(f, s) xlabel( Frequency (Hz) ); ylabel( Amplitude (db) )

12 KAPITEL 1. DATORÖVNINGAR Exercise 12: In section 1.1.2 it was described at which frequencies the signal side bands would end up and what happens to the reflected side-bands. It was also mentioned that the size of modulation index determines the amplitude of the side bands, but not how. The amplitude of the different side bands varies with modulation index and is determined by the so-called Bessel functions. For the side band of order n describe the amplitude variation of the Bessel function of order n. The MATLAB-function sideband plots Bessel functions of order zero up to six for modulation index zero to ten. The function also plot the Bessel function of order zero and the same Bessel function phase shifted 180. Execute the function sideband band in MATLAB and watch the functions. The second figure shows that if a side band to the left of the fundamental frequency would be reflected on the corresponding side-band on the right side of the fundamental frequency, these two cancel each other out. Depending on how the modulation index range varies it is also possible that the amplitude of the two side bands adds together. The Modulation index thus determines largely what frequencies will be heard and the volume. Because the side bands amplitudes behave as they do and that the side bands sometimes reflected is why, with FM synthesis, one can create very complex spectra.

Kapitel 2 Solution till computer exercise 2.1 Solution till computer exercise 4 syntk.m function cc = synthk(fc, fm, Aenv, Ienv, dur, fs) Cc = synth (fc, fm, Aenv, Ienv, dur, fs) Input parameters: Fc = carrier frequency in Hz Fm = modulationfrekvensen in Hz Aenv = is a constant which scales the amplitude Ienv = is a constant which scales the amplitude of the modulating signal Dur = signal duration in seconds Fs = sampling frequency in Hz tt = [0:1/fs:dur-1/fs]; create time array Implementation of the FM synth cc = Aenv.* cos(2*pi*fc.*tt + Ienv.* cos(2*pi*fm.*tt-(pi/2)) - pi/2); a different way of writing the function above, much slower! for k = 1:length(tt) cc(k) = Aenv * cos(2*pi*fc*tt(k) + Ienv * cos(2*pi*fm*tt(k)-(pi/2)) - pi/2); end synth.m function cc = synth(fc, fm, Aenv, Ienv, dur, fs) Cc = synth (fc, fm, Aenv, Ienv, dur, fs) Input parameters: Fc = carrier frequency in Hz Fm = modulationfrekvensen in Hz 13

14 KAPITEL 2. SOLUTION TILL COMPUTER EXERCISE Aenv = amplitude envelopen Ienv = envelope for modulation index Dur = signal duration in seconds Fs = sampling frequency in Hz tt = [0:1/fs:dur-1/fs]; create time array Arrange so that the length of time array match the length of the envelope if (length(tt)<length(ienv)) fix if tt is to short for i=length(tt)+1:length(ienv) tt(i) = tt(i-1)+1/fs; end elseif (length(tt)>length(ienv)) fix if tt is to long tt=tt(1:length(ienv)); end Implementation of the FM synth cc = Aenv.* cos(2*pi*fc.*tt + Ienv.* cos(2*pi*fm.*tt-(pi/2)) - pi/2); a different way of writing the function above, much slower! for k = 1:length(Ienv) cc(k) = Aenv(k) * cos(2*pi*fc*tt(k) + Ienv(k) * cos(2*pi*fm*tt(k)-(pi/2)) - pi/2); end bellenv.m function [Aenv, Ienv] = bellenv(a0, I0, tau, dur, fs) BELLENV generates the envelope of a bell sound [Aenv, Ienv] = bellenv (A0, I0, tau, dur, fs); input parameters A0 = a constant scale factor for the amplitude I0 = a constant scale factor for modulation index Tau = time constant specified in seconds Dur = envelopes varkatighet in seconds Fs = sampling frequency in Hz Returned: Aenv = exponentially decreasing envelope for amplitude Ienv = exponentially decreasing envelope for modulation index Create time array tt = [0:1/fs:dur-1/fs]; Generate envelopes Aenv = A0*exp(-tt/tau); Ienv = I0*exp(-tt/tau);

2.1. SOLUTION TILL COMPUTER EXERCISE 4 15 instfreq.m function instfreq(fc, fm, I0, Ienv, tau, dur, fs) Function calculating the instantaneous power of a bell sound And then plot the instantaneous frequency as a function of time tt = 0:1/fs:dur-1/fs; fi = fc - fm * Ienv.*sin(2*pi*fm*tt-pi/2) - (1/(2*pi))*I0*(1/tau)*Ienv; plot(tt, fi) woodwenv.m function [Aenv, Ienv] = woodwenv(att, sus, rel, fs) WOODWENV generates amplitude envelop and envelope for modulation index For woodwind instruments [Aenv, Ienv] = woodwenv (that, sus, rel, fs); Where to = attack time (s) Sus = sustain time (s) Rel = release time (s) Fs = sampling frequency (Hz) Returned: Aenv = amplitudenvelop Ienv = modulation index envelope NOTE: attack time is exponential, sustain time is constant, Release time is exponential ta = 0:(1/fs):(att-1/fs); Aenv = exp(ta/att*1.5)-1; Aenv = Aenv/max(Aenv); Aenv = [Aenv ones(1,sus*fs)]; tr = 0:(1/fs):(rel/2-1/fs); y3 = exp((rel/2-tr)/rel*3)-1; y3 = y3/max(y3)/2; y4 = 1-y3(length(y3):-1:1); Ienv = [Aenv ones(1,rel*fs)]; Aenv = [Aenv y4 y3 0]; len = min([length(aenv) length(ienv)]); Aenv = Aenv(1:len); Ienv = Ienv(1:len); Ienv = scale(ienv, -2, 4); brassenv.m function [Aenv, Ienv] = brassenv(att, dec, sus, rel, I0, fs)

16 KAPITEL 2. SOLUTION TILL COMPUTER EXERCISE [Aenv, Ienv] = brassenv (that, in dec, sus, rel, I0, fs) Function that creates an ADSR envelope for amplitude and modulation index NOTE: signal duration dur = to + dec + sus + rel dur = att + dec + sus + rel; tt = 0:1/fs:dur-1/fs; attlen = round((att/dur)*length(tt)); declen = round((dec/dur)*length(tt)); suslen = round((sus/dur)*length(tt)); rellen = round((rel/dur)*length(tt)); attp = 0:1/attLen:1-1/attLen; decp = 1:-(1/3)/decLen:(2/3)+(1/3)/decLen;length(decp) susp = (2/3)*ones(1, suslen); length(susp) relp = (2/3):-(2/3)/relLen:(2/3)/relLen; length(relp) drumenv.m function [Aenv, Ienv] = drumenv(dur, fs) Function that generates amplitude envelop and envelope of modulation index for drum sound tt = 0:1/fs:dur-1/fs; index = round(length(tt) * (1/8)); att = exp(tt(1:index)/4); rel = exp(-tt(index+1:end)/0.01); att = att/max(att); rel = rel/max(rel); Aenv = [att rel]; ilen = round(length(tt)*(1/8)); tmp = 1:-1/iLen:1/iLen; sus = zeros(1, round(length(tt)*(7/8))); Ienv = 25 * [tmp sus]; sideband.m function sideband Function to plot Bessel functions of order 0 up to 6 for the modulation index 0 up to 10. The function also plot Bessel functions of order zero and the same function phase shifted 180 degrees

2.1. SOLUTION TILL COMPUTER EXERCISE 4 17 tt = 0:0.1:10; for k = 0:6 J(:,k+1) = besselj(k, tt). ; end figure plot(tt, J); xlabel( Modulationsindex (I) ) grid disp( Press a key to draw up Bessel function of ) disp( zero-order and the same function phase shifted 180 degrees ) pause belopp = abs(j(:, 1)); fas = angle(j(:, 1)); Jinv = belopp.* exp(j*(fas-pi)); figure plot(tt, J(:, 1)) hold on grid plot(tt, real(jinv), r ); xlabel( Modulation index (I) ) scale.m function y = scale(data, alpha, beta) Function scaling the data according to: y = alpha * data + beta y = alpha * data + beta;