0% found this document useful (0 votes)
7 views11 pages

Implementation: 3.2.1 Sound Card

This document discusses the implementation of a system for real-time audio processing. It describes the hardware and software implementation, including how the program utilizes the computer's sound card and is adapted to different types of computers. It also explains how the program is written in Matlab and details the graphical user interface.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views11 pages

Implementation: 3.2.1 Sound Card

This document discusses the implementation of a system for real-time audio processing. It describes the hardware and software implementation, including how the program utilizes the computer's sound card and is adapted to different types of computers. It also explains how the program is written in Matlab and details the graphical user interface.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Chapter 3

Implementation
3.1 Overview
In this chapter we explain the practical implementation of the
system. The chapter is divided into two main parts, first the part of
the hardware implementation describes roughly how the
computer’s sound card works, as well as what has been done to
adapt the program to different types of computers.
The second part describes the implementation using Matlab.
Section 3.3.1 gives a brief introduction to Matlab, and mentions
some of the benefits that was utilized in the program. Section 3.3.2
explains the foundation of the main loop and finally Section 3.3.4
thoroughly explains the graphical user interface.

3.2 Hardware implementation


3.2.1 Sound card

No additional hardware components are needed to run the


program. The sampling and reconstruction is all carried out by the
sound card of the computer. A sound card typically consist of four
major components[20]:
• A DAC.
• An ADC.
• An interface to connect to the motherboard, typically a PCI
but could be a USB for external sound cards.
• Input and output connectors such as RCA-inputs and outputs,
3.5mm microphone jacks and headphone outputs.
Depending on the type of computer, the sound card can the
range from low end built-in sound cards in the motherboard to
advanced external sound cards for enthusiasts and professionals.
Typical features of a simple sound card could be a 2.1 stereo
sound output, a 5.1 surround sound input together with a 44.1 &
48kHz 16-bit playback and a 44.1 & 48kHz 16-bit recording[1]. In
Figure 3.1, a simple block diagram of a sound card can be seen[17].
Figure 3.1: A simplified block diagram of a sound card.

In Figure 3.1 the block ASP/CSP stands for Advanced/Creative


Signal processor. Some sound cards have a built in dedicated signal
processor that handles some operations instead of the computer’s
CPU[20].

3.2.2 Adaption to multiple types of computers


Several precautionary measures has been taken to ensure that as
many types of computers as possible can handle the program. The
most profound effect on performance is to draw the plots. The
option “Reduced visual playback” reduces the frame update
frequency of the plots by four times. The vectors that contain the
samples of each frame are also reduced in size by factor four,
reducing the algorithm’s computations as described in section 2.2.
Some vector’s lengths are also limited. Both input and output time
vectors are limited to contain information from the past two
seconds to reduce in overhead.
Another limitation is that the prefabricated filters are loaded from a
separate file once the program starts up. Even though loading
from a file might not be the fastest operation, this was found to
be faster than creating the filters from scratch every time the
program started.

3.3 Software implementation


3.3.1 Matlab
All of the program and all of the code was written in Mathworks
Matlab 2015b. Matlab is, in contrast to for example C or C++, a
high level language based on matrices. With over 30 years since
Matlab started taking shape, it has grown to one of the most used
programs for engineering simulations and modelling. Matlab is
complemented by Simulink which is a graphical programming
language where instead of typing code the user selects boxes
and elements representing different operations sorts and draws
connections between these. Matlab and Simulink can also be
combined to work together. Matlab also includes various toolboxes
with functions and objects that can be created to get a project started.
The toolboxes are related to various engineering fields such as
aerospace, electronics, control theory and many more. This makes
Matlab one of the most popular software programs for engineers
and scientists[12][18].
In this project the many functions of sampling from a file and the
mic, filtering and recon- structing the signal, and the DSP toolbox
were used. The DSP toolbox provides analyzing tools such as Time
Scope objects, Spectrum Analyzer objects and filter constructing al-
gorithms. Only a small part of these functions are used in the
finished project, but many of them were used in the development
so that the focus could be put onto one problem at a time[5].

3.3.2 Generation of code


To construct the program, various tools in Matlab have been used.
To create the Graphical User Interface (GUI), the Matlab
environment “Guide” has been used. This is a tool to help create
GUI:s more creatively by instead of typing code specifying where to
put buttons and axes, they can be dragged and placed on a canvas
which decreases the time and effort tremendously when working
with a complicated GUI. The main GUI’s construction in “Guide” is
shown in Figure 3.2.

Figure 3.2: The main GUI in the creative setting “Guide”.

The base of the program is the main loop. A flowchart of the main
loop can be seen in Figure 3.3. The simplified version of the
structure of the loop can be seen in Figure 3.4. This pseudocode
describes the test bench upon which the main loop is built. The
program clearly has three phases. The program is first initialized,
the “Audiorecorder” object is created, variables are loaded as well
as memory for vectors and arrays is preallocated. Then, in the main
loop, the sound is sampled and divided into frames. At the end of
the loop there is usually either some plots created or some sound
is sent to tha audio output.

Figure 3.3: The loop that runs while the On/Off toggle button is pushed.

Figure 3.4: Pseudocode of the base of a testbench, the foundation of the main
loop.
The middle of the loop is where the signal is processed, either by
filtering or by computing the FFT is performed. At the end of the
program there is a terminate phase, where in this case the
“Audiorecorder” object is released.

3.3.3 Filter design algorithms

Since this program was used for educational purposes there should
be different ways to construct and filter the audio. The different
ways are listed below.
• The main way of constructing a filter is by typing in the coefficients of the
filter an
and bn in the text boxes of the “Own filter design”-control panel.
• Create a Matlab filter in the “Matlab filter”-control panel.
• Create a Matlab function (see Section 3.3.4) and typing the
name of the function in the “Own filter function”-text box in
the “Filter source” control panel.
When it comes to designing the filter for the “Own filter design”,
it is up to the user to find the coefficients. Matlab then uses the
function “y = filter(b,a,x)” to calculate the output y from input
signal x with the help of coefficients b and a.
“Matlab filter” uses the “Filter Design assistant” to calculate a
filter object which is also filtering with the help of “y =
filter(filterobject, x)”. This provided tool Matlab includes design
methods such as Equiripple, Kaiser window, Butterworth,
Chebyshev Type I and Type II and Elliptic.
The prefabricated filters have various design methods. The basic
FIR and IIR filter types have been created with the help of Matlab’s
“filterbuilder”, which is slightly more com- plicated than “Filter
Design Assistant”.

3.3.4 Graphical user interface


The most important part of the program is the graphical user
interface. The main GUI can be seen in Figure 4.1, and the other
two can be seen in Figure 4.2 and 4.3. In this section the different
parts of the GUI will be reviewed to give an idea of how the
program is used, in complement to the flowchart in Figure 1.1.
All of these separate control panels have an information button,
which open a separate help dialog with a small text describing the
functionality of the control panel as well as some of the limitations.

On/Off
The On/Off control unit consists of three main interaction sources.
There is the On/Off toggle button which starts the main loop
described by the flowchart in Figure 3.3. There is also a pause
toggle button which can be used at any point to pause and restart.
The pause button activates a spin loop in the main loop. While
the pause button is pushed the user could enter either the
magnified timeplot GUI or the magnified FFT plot GUI. Third there
is the Reduced visual playback tick box which is ticked by default.
This is described in more detail in Section 3.2.2.
Source
There is the option whether to sample from a file or whether to
sample from the mic input of the computer. Both of them use the
same algorithm and both of them process the music in real time.
The mic input is the default and the file input is merely thought
of as a complement to increase the flexibility of the program. The
user chooses how to

Figure 3.5: The main GUI’s on/off control unit.

sample the music and if the file input is choosen, the file name has
to be entered as text in the “File name”-text box. The entire file
name has to be entered, including the file type extension.

Figure 3.6: The source control panel.

Miscellaneous
Setting the sampling rate is only an option while the filter
source is set to mic input. When the main loop is running, the
sampling rate text box is blocked from usage but the user can
still read out which sampling rate is used. It is the file’s sampling
rate that sets the sampling rate at which the program samples the
sound. The default is 44100 Hz. The gain works in a similar manner
as a volume knob. By pressing the arrows, the gain multiplier can
be increased or decreased. The user can also choose to enter a
non-integer value by typing the value into the textbox.
Figure 3.7: The misc control panel.

Own filter design


Since both IIR filters and FIR filters can be expressed as a fraction
(see Section 2.3.1 and 2.3.2) the “Own filter design” panel is
supposed to be self explanatory. The coefficients
of the filter are entered in the text box separated by a space
(ascii 32). This can be done at any time. However, the main loop
has to be off to press the push button “Update filter”. By pressing
the “Update filter”-button the coefficients are saved as the “Own
filter design” object, making it possible to use the filter to filter the
sound. The idea is that the student has constructed a filter on paper
and wants to apply it in a real world application. The “Own filter
design” panel lets the student apply the filter easily on some signal.
The “Visualize own filter” is another tool to make the student
understand the properties of the filter (s)he has constructed by
opening up the built in Matlab GUI “Filter Visualization Tool”. In this
environment the student can acquire information about the
magnitude response, phase response and other important
information about the structure, stability and type.

Figure 3.8: The own filter design management control panel.

Matlab filter
When students will construct filters in the future, there is a great
chance that companies or others will have prefabricated filter
algorithms and programs for this purpose. Also, when discussing
filter properties with coworkers and fellow students it is important
that the terminology is correct. The “Matlab filter” panel lets the
student construct a filter and apply it without the tedious works of
calculating the coefficients by hand. The “Create Matlab filter”-push
button allows the user to create a filter using Matlab’s “Filter
design assistant” by specifying parameters to meet requirements.
This gives an incentive to learn the terminology used in filter
specifications as well as common construction algorithm names.
The “Change Matlab filter”-push button lets the user change the
parameters of the already constructed filter and “Visualize Matlab
filter” opens up the “Filter Visualization Tool” to acquire the
information already mentioned in Section 3.3.4. The text below
gives some simple information about the filter, but the text string
mostly aims to indicate whether a filter has already been created
or not.
Figure 3.9: The matlab filter design panel.
Filter source
The filter source control panel allows the user to choose the filter source. The
options are:
• Own filter design
• Matlab filter (“Let Matlab do it”)
• Prefabricated filter
• Own filter function
“Own filter design” and “Let Matlab do it” uses the filter methods described in
Section
3.3.4. “Prefabricated filter” lets the user choose between a
selection of filters from a pop- up menu, some FIR filters, some IIR
filters and some simpler filters with sound effects. “Own filter
function” lets the user construct a function script in Matlab which
can receive an input vector, perform filtering or whatever the user
wishes to do with the samples, and return a vector of the same
size. This option is suitable if the user wishes to use more
complicated filters. This invites the user to play and create
filters with sound effects, and cascaded filters with endless
possibilities. The only criterion to create such a filter is as
mentioned, that the size and shape are the same for input and
ouput signal, and the function header must be as described in
Equation 3.1 with a header that handles an indexation variable. The
reason for this is that many more advanced filter such as a flanger
for instance has a periodical feature to create these sound effects.
When Matlab divides the samples into frames, these frames
represent such a short period of time in a song that these periodical
features do not have time to create an effect. A flanger has a
periodical feature with a period of around 20-40ms[10], a frame of
1024 samples sampled at 44100Hz
represents a time from t = 0 seconds
44100 to t = 1
·1024 = 0.232
seconds. The flanger then needs to keep track of its own
periodicity when the next frame arrives so that the effect
can continue without interruptions that would worsen the sound.
The filtering method can be changed anytime while the program is
running, even if the main loop is activated. To activate filtering,
the tick box “Apply filter” needs to be ticked.
function y = testfilterfunction(audioIn, index)

(3.1)
Figure 3.10: Filter source control panel.

Impulse response
The user can plot a simple plot in the axes inside the “Impulse
response” panel. The interface is very limited and there are no
possibilities for interaction. The panel is merely there to give the
user a rough idea of how the impulse response of the filter might
look like. The reason for this is that in Matlab’s “Filter Visualization
Tool” there already are possibilities of acquiring this information.

Figure 3.11: Impulse response response panel with axes.

Spectral analysis
The spectral analysis control panel is designed to communicate to
the user the sufficient information needed to be able to know what
type of filter is needed. The top axes plots the FFT of the input
signal and the bottom the output signal. It is possible to change the
visible range. However only the x-axis can be changed and only
while pause is activated. So either the program has to be paused or
the “Spectral analysis” pause toggle button needs to be pressed. If
the user needs more information, while pause is active (s)he can
press the magnifying glass, opening up the spectral analysis’s GUI.
The GUI is seen in Figure 4.2. With this interface open the user
can change both the limits of the x-axis and the y-axis to have a
closer look. However, only information from the present frame is
available.
Figure 3.12: The spectral analysis control panel.

Time plot of input signal

The “Time plot”-panel works in a similar manner as the “Spectral


analysis”-panel in Section 3.3.4. Though, in the main GUI only
the input signal is available to look at. To be able to see the time
plot of the output signal, the user has to use the magnifying glass
push button to open the “Time plot”-GUI. This GUI looks very
similar to the “Spectral analysis”-GUI, with possibilities to change
the limits of both the x-axis and the y-axis, though only information
from the past 2 seconds is available as described in Section 3.2.2.

Figure 3.13: Time plot axes with controls.

Chapter 4
Results
4.1 Software
The main program’s graphical user interface can be seen in Figure
4.1. On top of the main GUI, there are also two more simple GUIs
that can be opened by pressing the magnifying glass next to some
of the plots while the program is paused.

Figure 4.1: The main program’s graphical user interface.


One problem that was encountered was the way that variables
were passed between func- tions in the program. Matlab is based
on Java but passing variables inside the GUI is different from having
instance variables connected to objects. In this program, variables
are passed by the use of the handles-structure, see Appendix B.1.
This was also a problem when it came to filtering with the
prefabricated filters due to passing the filters both fast and
elegantly. Constructing six filters in the startup of the program
would not be ideal either, this would at least double the startup
time. These filters are preconstructed and loaded from a separate
file instead.

Figure 4.2: The GUI of the magnified FFT plot.

Figure 4.3: The GUI of the magnified time plot.

You might also like