Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Putting Theory into Practice with Simulink

John Turner, Joseph P. Hoffbeck


University of Portland

Abstract

Many students prefer to learn by induction (starting with specifics and working toward the
general theories). However, engineering classes are traditionally taught with a deductive
approach (starting with general theories and working toward specifics). This paper discusses
how the software package Simulink can be used to bring an inductive element into a digital
signal processing (DSP) course which allows the students to experiment with the theory and to
directly experience the results of the processing. This process gives the students immediate
feedback on whether they have correctly understood the theory, and allows the students to be
active learners. An example project is described that allows the students to implement the audio
processing tasks of flanging, chorusing, and reverb without any programming, and allows the
students to hear the results in real-time.

Background

Digital signal processing (DSP), like many courses in engineering, is very theoretical and
mathematical, yet has many practical and interesting applications. Often the course is taught in a
deductive style where the general theories are presented and then applications of the theories are
explored. Until they study the applications, many students find it difficult to follow the
mathematical presentation of the theory, and may become discouraged.

One solution to this problem is to give the students a set of tools that allow them to
experiment with the theory to verify the theory and to test their understanding of the theory. The
students can then become active learners engaged with the material by designing their own
experiments, making observations, and reflecting on the results.

The software package Simulink from The MathWorks, Inc. can be used to model and
simulate a variety of systems in a high-level, block diagram format without any low-level
programming. Many papers discuss how Simulink can be used as an effective teaching tool in
areas such as electronic control systems,1,2,3,4,5,6,7,8,9,10 dynamic systems,11,12,13,14,15,16 mechanical
systems,17,18,19,20 microcontrollers,21 linear systems,22,23 and DSP 24,25,26,27. This paper is within
the scope of DSP and exclusively covers the processing of audio signals. Such processing is
brought up in a musical context by recreating popular audio effects, an approach that is not
widely taken in this field. What is more, this paper describes specific parameters, how to adjust
them in Simulink, and how they theoretically affect the filter in question, making it a practical
guide for any reader to get up and running quickly. By using such an approach, the potentially
Page 10.1046.1

difficult and abstract realm of signal processing is brought down to earth. The end result is an

Proceedings of the 2005 American Society for Engineering Education Annual Conference & Exposition Copyright
© 2005, American Society for Engineering Education
educationally rich project that reaches a very broad audience ranging from actual musicians to
popular music enthusiasts, which covers the majority of any student population.

Simulink's usefulness is further enhanced by the Real-Time Workshop package (also


from The MathWorks, Inc.) that converts a Simulink model into a C-language program that can
be run directly on a personal computer or on a DSP demonstration board in real-time. Thus the
student can build and test a model of a system in Simulink's block diagram format, and then
compile it and run the program on an actual hardware platform without any low level
programming. This process converts the model into an actual system that runs in real-time. For
subjects such as DSP, where the system can be constructed in a laboratory setting, the student
can then use real inputs to the system and observe the results of the actual system running in real-
time, which is more engaging and realistic than working with a simulation. This process also
gives the students immediate feedback and tests their understanding of the theory behind the
system. The experience with the real system should help them understand the context of the
theory and further motivate them to learn the material.

Most of the topics in DSP can be supported using this technique including spectrum
analysis, filtering, effects of finite word length, etc. In order to illustrate this technique, an
example project is described that implements the music processing tasks of flanging, chorusing,
and reverb, and allows the students to immediately hear the results of the system that they have
modeled, which should especially benefit the students who prefer sensory information28.

Flanging Explained

A flanger is a filter that alters the frequency content of a signal by sampling its input,
delaying it with a variable delay, and then adding the result to the unmodified input as shown in
Figure 1.

x(t) + y(t)

Variable Delay x(t-∆t)


∆t

Figure 1: Basic Flanger

A low frequency oscillator (LFO) is used to control the value of the delay. Through destructive
and constructive interference, certain frequencies are either amplified or attenuated when the
signals are added. The filter’s frequency response for a fixed time delay is given by the
following equation:
Page 10.1046.2

Proceedings of the 2005 American Society for Engineering Education Annual Conference & Exposition Copyright
© 2005, American Society for Engineering Education
⎛ 2πf∆t ⎞
H ( f ) = 2 cos⎜ ⎟ (1)
⎝ 2 ⎠

where ∆t is the instantaneous time delay determined by the LFO. The attenuation of certain
frequencies forms notches in the frequency spectrum that make the flanger resemble a comb
filter. The magnitude of the filter's frequency response for ∆t = 1 mS is shown in Figure 2.

M a g n it u d e d o f F re q u e n c y R e s p o n s e w it h ∆ t = 1 m S
2

1 .8

1 .6

1 .4

1 .2
|H(f)|

0 .8

0 .6

0 .4

0 .2

0
0 500 1000 1500 2000 2500 3000 3500 4000
F re q u e n c y (H z )

Figure 2: Magnitude of Frequency Response with ∆t = 1 mS .

It is important to note that a flanger differs from a traditional comb filter in that the
frequencies that it attenuates vary with time. This is the direct result of its variable delay which
causes the “teeth” of the comb filter to continuously move up and down the spectrum29. The
attenuated frequencies (in Hz) are given by the following equation:

2n + 1
fz = (2)
2∆t

where n = 0, 1, 2, ... Thus, the frequencies that are attenuated are harmonically related and
depend on the instantaneous delay30.

This constant change of destructed frequencies, or the continual sweeping of the notches
in the frequency response, is perceived by the human ear as a “whooshing” sound that is
characteristic of common flangers. If the instantaneous delay is greater than 50 mS, the resulting
signal could be perceived as an echo, however, in a flanger, the delay is usually less than 10 mS,
making it too fast for the ear to distinguish31.
Page 10.1046.3

Proceedings of the 2005 American Society for Engineering Education Annual Conference & Exposition Copyright
© 2005, American Society for Engineering Education
It is also important to note that because of the presence of a variable delay, the frequency
response is not actually represented by equation (1) because the filter is not a time-invariant
system. However in most introductory signals and systems courses study is limited to linear,
time-invariant systems. For our purposes, it is sufficient to conceptualize the flanger at any
given time as a comb filter, and to keep in mind that the frequencies that are eliminated by this
filter are a function of the value of the instantaneous time delay ∆t , which in turn is controlled
by a LFO.

Implementation in Simulink

The flanger, and almost any DSP system, can be easily implemented in Simulink using
both the standard Simulink blockset and the DSP blockset. The overall system block diagram
can be seen in Figure 3. The values of the parameters for each block are set by double-clicking
on the block and typing the values into an easy-to-use dialog box. No programming is required.

Figure 3: Simulink Block Diagram for a Windows Sound System Based Flanger

When implementing such a system, two options can be exercised when choosing the
input and output sources: the windows sound system or a DSP board. Using the windows sound
system provides an easy-to-use platform that can operate in real time and does not require any
expensive external hardware. Figure 3 demonstrates such a setup where the input is an 8 KHz
wave file and the output is sent to the computer’s speakers. The input could just as easily be a
microphone or line input. This setup is ideal for the immediate testing of parameters as only a
very short time is required to compile the model, and the flanger can be run in real-time on a
standard PC.

The model exactly follows the theoretical description. Variable delay is made possible
by the Variable Fractional Delay block found in the DSP blockset. A DC constant is necessary to
control the delay parameter of the flanger which dictates the average value of the LFO. It is
important to ensure that all blocks are set to process the same number of samples per frame and
are set to the proper sampling rate (as dictated by the given wave file). The same model can be
Page 10.1046.4

found in the Audio Processing Demos in the Matlab help file.

Proceedings of the 2005 American Society for Engineering Education Annual Conference & Exposition Copyright
© 2005, American Society for Engineering Education
The flanger can also be run in real-time on a DSP demonstration board. To allow the use
of a DSP board, the only necessary changes to the model are to the input and output blocks of the
system. Inputs and outputs specific to the board being used should be implemented. If using a
DSP board, the Simulink model can be compiled and run in conjunction with Real-time
Workshop to create a truly real-time flanging C program. This additional step of using a DSP
board requires more setup and work, but can be valuable to show the system running on a DSP
chip instead of a general purpose computer.

Common Parameters

There are several ways to customize how a flanger filters a given signal. A great place to
start for a classic flange is to set the DSP constant to 25, the LFO frequency to 0.7 Hz, and the
amplitude to 20. Simulink has the ability to work with frames of data, and another factor that
influences flange quality is the number of samples taken per frame. A good value to start with is
256 samples per frame as any number lower than 256 results in an indiscernible overall effect.
The number of samples per frame only needs to be adjusted on the input block and the LFO
block. Below are some of the most common flanger parameters29 as described by musicians and
how they relate to the Simulink model parameters:

Sweep Depth also known as width, is the height of the delay control signal which in our case is
twice the amplitude of the LFO. The sweep depth defines the maximum and minimum values
over which the effective delay varies and can be set in the amplitude field of the DSP function
generator block. An amplitude value around 20 creates a pleasant, traditional flanging sound.
The larger the sweep depth, the more prone the model becomes to pitch modulation. For a 44.1
KHz input file and sampling with 256 samples per frame, noticeable pitch modulation could be
heard with amplitude starting at 100 samples.

Delay specifies the minimum delay reached by the LFO. This parameter is indirectly adjusted by
the DC offset block shown in Figure 3 and its value is the difference of the DC constant and the
amplitude of the LFO. Delay acts as a vertical shift for the sweep depth, causing the total delay
to range over a higher or lower set of values. It is important to reference the value of “maximum
delay” as set in the variable fractional delay block of the model when adjusting the Delay
parameter. If the maximum delay of the LFO (the sum of the DC constant and the amplitude of
the LFO) exceeds the maximum delay parameter, the flange will be cut off. This is audibly
indicated by a clicking noise whenever the max delay is reached, and then an absence of the
effect until the LFO returns back to an acceptable level.

Dry Mix is the amount of gain applied to original signal before it is mixed with the delayed
signal (see Figure 3). This is adjusted in Simulink by changing the value of the gain parameter
on the original signal. This parameter affects the severity of the effect and is important in
relation to the Wet Mix. If the dry mix is significantly larger than the wet mix, for example by a
factor of ten, then the effect will be nearly eliminated as there is no wave interference and the
result is dominated by the original signal.
Page 10.1046.5

Proceedings of the 2005 American Society for Engineering Education Annual Conference & Exposition Copyright
© 2005, American Society for Engineering Education
Depth or Wet Mix is the amount of gain applied to the delayed signal before it is added to the
original input (see Figure 3). This is adjusted in Simulink by changing the value of the gain
parameter on the delayed signal. An increase in the wet mix will increase the severity of the
flange effect, unless it is driven too high. If the wet mix is significantly higher than the dry mix,
the resulting output will be dominated by the delayed signal. This can be interesting if the
parameters for the LFO are set properly. For example, an amplitude of 20 and a frequency of 6
Hz will result in a slight whammy effect where the pitch oscillates rapidly. Also, the same
amplitude with a rate of 20 Hz or above creates a mechanistic warbling effect where the pitch
changes very rapidly.

Rate is the frequency of the LFO which governs how quickly the flanger cycles through the
delay range. This parameter is adjusted by changing the frequency setting in the DSP signal
generator (LFO). As explained in previous sections, rate is very important to the overall flanging
effect. A classic flange has a frequency of around 0.7 Hz whereas a frequency of around 200 Hz
results in a space-like warble.

Extension to Other Effects

As hinted by the dramatic results that occur when changing the various parameters of the
flanger, this project can simulate more than just one effect. Several other delay-based effects
such as chorus and reverb can also easily be implemented in Simulink with minimal change to
the original model.

Chorusing is nearly identical to flanging and is only different in the delays it imposes on
the input signal. A classic flange has a delay range between 0 – 10 mS whereas a chorus has a
range from around 30 - 50 mS32. To implement this range in Simulink with the given model, set
the DC constant to 320, and the amplitude of the LFO to 80. There is some room for adjustment,
however these values are adequate for a pleasant chorus effect.

There are other approaches to creating a chorus effect, such as that proposed by Dodge
and Jerse30. Their proposal for creating a chorus is to add together several signals, each a
randomly delayed version of one input signal. Each delay ranges from 10 - 50 mS and is
determined by a random noise. This technique could serve as another project for interested
students.

Reverb is another delay-based effect, however the delay is constant rather than shaped by
an oscillator. Also, this effect is not reliant upon the constructive and destructive interference of
wave addition. Instead, the original sound is played once and then a delayed copy is iteratively
sent to the output. Each iteration passes through a feedback loop with sub-unity gain that
eventually causes all sound to fade out. Reverb serves to model sound reflection in a natural
space, such as a large amphitheater or a hall which is basically an echo with decaying repeats32.
The Simulink block diagram for a Reverberation model can be seen in Figure 4.
Page 10.1046.6

Proceedings of the 2005 American Society for Engineering Education Annual Conference & Exposition Copyright
© 2005, American Society for Engineering Education
Figure 4: Simulink Block Diagram for a Reverberation Model

Conclusion

The software package Simulink is a useful tool that allows students to experiment with
DSP algorithms and to experience the results in real-time. Simulink can be used to illustrate
most of the topics commonly taught in DSP courses without any programming. To illustrate this
technique, a project was presented that implements a flanger, which is a delay-based audio effect
that is common in popular music and movies. Using the DSP blockset in Simulink allows the
students not only to build a real-time model, but also to change every parameter so the sound is
completely customizable. This feature allows students to experiment with the model and get
immediate feedback on how well they understand the theory. The model can also be extended to
other popular audio effects such as chorusing and reverb.

References

1. Ossman, Kathleen A. K., Teaching state variable feedback to technology students using MATLAB and
SIMULINK, ASEE Annual Conference Proceedings, Jun 16-19, 2002, p 2471-2481.
2. Cheng, Frank S.; Zhao, Lin, Developing a MATLAB-based control system design and analysis tool for
enhanced learning environment in control system education, ASEE Annual Conference Proceedings, Jun
20-23, 2004, p 3103-3116.
3. Martinez, Denise; Bolton, Robert; Zoghi, Behbood, Embedded real-time controls through application,
Proceedings - Frontiers in Education Conference, v 2, Nov 10- 13, 1999, p 12b6-20 - 12b6-22.
4. Saadat, Hadi; Williams, Stephen, Innovations in undergraduate control system instructional laboratory,
ASEE Annual Conference Proceedings, Jun 20-23, 2004, p 7351-7363.
5. Dalton, Jeffrey S.; Stutts, Daniel S.; Montgomery, Robert L., Mini-lab projects in the undergraduate
classical controls course, ASEE Annual Conference Proceedings, Jun 22-25, 2003, p 9329-9337.
6. Rodriguez, Armando A., Development of Arizona State University's MoSART-FAME research program,
ASEE Annual Conference Proceedings, Jun 16-19, 2002, p 11-16.
7. Eydgahi, Ali; Fotouhi, Mohammad, A fuzzy knowledge-based controller to tune PID parameters, ASEE
Annual Conference Proceedings, Jun 20-23, 1999, p 111-122.
8. Anakwa, Winfred K. N.; Thomas, Dion; Jones, Scott; Bush, Jon; Green, Dale; Anglin, George; Rio, Ron;
Sheng, Jixiang; Garrett, Scott; Chen, Li, Development and control of a prototype pneumatic active
suspension system, ASEE Annual Conference Proceedings, Jun 18-21, 2000, p 1939-1951.
9. Plett, Gregory L.; Schmidt, David K., Multidisciplinary lab-based controls curriculum, ASEE Annual
Conference Proceedings, Jun 24-27, 2001, p 7341-7352.
10. Garcia, R. Murillo; Wornle, F.; Stewart, B.G.; Harrison, D.K., Real-time remote network control of an
Page 10.1046.7

inverted pendulum using ST-RTL, Proceedings - Frontiers in Education Conference, v 1, Nov 6-9, 2002, p
T2E/18-T2E/23.

Proceedings of the 2005 American Society for Engineering Education Annual Conference & Exposition Copyright
© 2005, American Society for Engineering Education
11. Klegka, John S.; O'Donovan, Thomas E., Using SIMULINK as a design tool, ASEE Annual Conference
Proceedings, Jun 16-19, 2002, p 8505-8517.
12. Bolton, Robert W.; Zoghi, Behbood, Enhancing system dynamics instruction for technologists with
simulation, ASEE Annual Conference Proceedings, Jun 22-25, 2003, p 11408-11411.
13. Avitabile, Peter; Goodman, Charles; Hodgkins, Jeff; White, Karl; Van Zandt, Tracy; StHilaire, Gary;
Johnson, Tiffini; Wirkkala, Nels, Dynamic systems teaching enhancement using a laboratory based hands-
on project, ASEE Annual Conference Proceedings, Jun 20-23, 2004, p 4129-4144.
14. Avitabile, Peter; Goodman, Charles; Van Zandt, Tracy, Development of a measurement system for
response of a second order dynamic system, ASEE Annual Conference Proceedings, Jun 20-23, 2004, p
3559-3569.
15. Perdikaris, George A., Computer control of machines and processes, ASEE Annual Conference
Proceedings, Jun 18-21, 2000, p 4219-4227.
16. Saco, Roberto; Pires, Eduardo; Godfrid, Carlos, Real time controlled laboratory plant for control education,
Proceedings - Frontiers in Education Conference, v 1, Nov 6-9, 2002, p T2D/12-T2D/16.
17. Smaili, Ahmad; Zeineddine, Firas, SoftLink: A matlab/simulink based code for the analysis, synthesis,
optimization and simulation of mechanisms, ASEE Annual Conference Proceedings, Jun 22-25, 2003, p
10949-10959.
18. Azad, Abul K. M.; Tokhi, M.O.; Pathania, A.; Shaheed, M.H., A matlab/simulink based environment for
intelligent modelling and simulation of flexible manipulator systems, ASEE Annual Conference
Proceedings, Jun 20-23, 2004, p 9547-9560.
19. Metzger Jr., Richard P.; Rodriguez, Armando A., An Interactive Modeling, Simulation, Animation, and
Real-Time Control (MoSART) flexible Inverted Pendulum Environmnet, ASEE Annual Conference
Proceedings, Jun 16-19, 2002, p 1-9.
20. Esposito, Joel M.; Feemster, Matthew G.; Watkins, John M., Role of a matlab real-time hardware interface
within a systems modeling course, ASEE Annual Conference Proceedings, Jun 20-23, 2004, p 12317-
12331.
21. Lee, Sang-Hoon; Li, Yan-Fang; Kapila, Vikram, Development of a matlab-based graphical user interface
environment for PIC microcontroller projects, ASEE Annual Conference Proceedings, Jun 20-23, 2004, p
3539-3557.
22. Yousuf, Asad; Luo, Jiecai; Huang, Chun Ling, Using the SIMULINK as a teaching tool, ASEE Annual
Conference Proceedings, Jun 20-23, 2004, p 15179-15188.
23. Coyne Jr., Paul J., A role for SIMULINK in a continuous-time signals and systems course, ASEE Annual
Conference Proceedings, Jun 20-23, 2004, p 12311-12316.
24. Kozick, Richard J., Undergraduate design projects in a laboratory for real-time signal processing and
control, ASEE Annual Conference Proceedings, Jun 23-26, 1996, p 3561-3568.
25. Spinelli, John M., The signals and systems toolbox: Comparing theory, simulation and implementation
using MATLAB and programmable instruments, ASEE Annual Conference Proceedings, Jun 22-25, 2003,
p 2239-2246.
26. Ramachandran, Ravi P.; Head, Linda M.; Mandayam, Shreekanth A.; Schmalzel, John L.; Chin, Steven H.,
Laboratory experiments unifying concepts in the communications, digital signal processing (DSP) and very
large scale integration (VLSI) courses, ASEE Annual Conference Proceedings, Jun 22-25, 2003, p 4283-
4310.
27. Amir, Noam, Role of graphical programming languages in teaching DSP, IEEE International Conference
on Acoustics, Speech and Signal Processing(ICASSP) - Proceedings, v 6, Jun 5-9, 2000, p 3514-3517.
28. Richard Felder and Linda Silverman, Learning and Teaching Styles in Engineering Education, Engineering
Education, Vol. 78, April 1988, pp. 674-681.
29. Lehman, Scott. “Flanging”. Harmony Central – Effects Explained. 1996.
http://www.harmony-central.com/Effects/Articles/Flanging/
30. Dodge, Charles and Thomas A. Jerse. Computer Music: Synthesis, Composition, and Performance. New
York: Schirmer Books, 1984, pp 303-305.
31. Cronin, Dennis "Examining Audio DSP Programs," Dr. Dobb's Journal, pp 78-83, Vol. 19, Issue 216, July
1994.
32. Lehman, Scott. “Reverberation”. Harmony Central – Effects Explained. 1996.
Page 10.1046.8

http://www.harmony-central.com/Effects/Articles/Reverb/

Proceedings of the 2005 American Society for Engineering Education Annual Conference & Exposition Copyright
© 2005, American Society for Engineering Education
Biographical Information
JOHN TURNER

John Turner is an undergraduate student at the University of Portland seeking an B.S in Electrical
Engineering. He has completed research regarding digital implementations of audio signal processors as well as in
chaos implemented in mechanical and electronic systems.

JOSEPH HOFFBECK

Joseph P. Hoffbeck is an Associate Professor of Electrical Engineering at the University of Portland, in


Portland, Oregon. He received his Ph.D. from Purdue University, worked for Lucent Technologies in digital cellular
and PCS systems, and is a member of ASEE and IEEE. His technical interests include communication systems,
digital signal processing, and remote sensing.

Page 10.1046.9

Proceedings of the 2005 American Society for Engineering Education Annual Conference & Exposition Copyright
© 2005, American Society for Engineering Education

You might also like