Sunday, 4 January 2015

New DSP Software Updates

Prompted by the release of wxWidgets v3.x I have used the holidays as an opportunity to update and test a load of my software libraries and utilities.
They can be downloaded from here :

SigLib (v8.53) DSP Library : http://www.numerix-dsp.com/siglib.html. Includes some new functions for Q format integer support and it has been tested on Mac OS X and Raspberry Pi.

The following example programs and libraries have also been updated and these can be downloaded from http://www.numerix-dsp.com/files/ :

    System Analyzer- V2.10 - A simple System Analyzer that uses wxWidgets V3.0.2 (A free portable GUI library), NGL, PortAudio (A free portable Audio I/O library) and can optionally use SigLib. This application includes the full GUI source code.

    Numerix Host Library - V3.00 - A library of host I/O routines, including full source code. Functions include console and File I/O, including .WAV files. These functions can be used on any OS (UNIX, Windows etc.) and also on any other embedded processor or DSP that supports console and file I/O via the debug environment. These functions can also be used with Gnuplot/C to run any of the SigLib example programs.

    Numerix Graphics Library - V2.60 - A simple library of graphics routines for the wxWidgets V3.0.x based GUI applications. Full source code is included.

If you have found this solution useful then please do hit the Google (+1) button so that others may be able to find it as well.

Numerix-DSP Libraries : http://www.numerix-dsp.com/eval/

Copyright © 2015 Delta Numerix

Friday, 2 January 2015

DSP Tech Brief : Introduction To The Q Format Number System

One area of Digital Signal Processing that causes sleepless nights for Design Engineers is when they first encounter fixed point maths. Issues such as overflow and underflow,. that are automatically resolved when using floating point numbers, can add an extra layer of complexity when implementing fixed point algorithms.
Unfortunately in embedded system design it is typically not possible to avoid fixed point issues because floating point silicon requires many more transistors, particularly to implement the multiplier, and hence is more expensive and slower than equivalent fixed point implementations.
There are many different ways to represent numbers using integers including signed 2's Complement, Signed Offset Binary etc. but one of the most useful is the Q Format.
Q format numbers split the fixed point word into two components - the integer (m bits) and fractional (n bits) parts to give a number represented in the format m.n. This makes the word length of the integer equal to m+n bits.
The Q format allows the algorithm to be implemented using fixed point operations but requires the designer to manage the data both into and out of the algorithm.

A regular integer number creates overflow during the multiplication and addition operations.
Some processors provide a partial workaround for this by allowing optional use of fractional numbers for multiplication, in which case underflow occurs but this still doesn't avoid overflow with addition operations.

8 bit integer multiplication example

Treating fixed point numbers as integers means that we have the possibility of overflow.
The maximum 8 bit signed number is 127 (0x7f)
127 x 127 = 16129 which is a 16 bit number and has overflowed our 8 bit word length

8 bit fractional multiplication example

Treating fixed point numbers as fractions means that we have the possibility of underflow but not overflow.
The maximum 8 bit signed number is 127/128 = 0.9921875 (0x7f)
0.9921875 x 0.9921875 = 0.98443603515625 which has not overflowed our 8 bit word length but the lsbs will underflow to give us 126/128 = 0.984375.

8 bit (2.6) Q format example

We have 2 bits for the integer (m) and 6 bits for the fractional (n) components.
The value of 1.0 is represented by 0b01000000 (0x40)
If we now represent the following numbers in 2.6 Q format :
  2.0  - 0b10000000 (0x80)
  1.5  - 0b01100000 (0x60)
  0.5  - 0b00100000 (0x20)
  0.25 - 0b00010000 (0x10)
  0.75 - 0b00110000 (0x30)

We can now perform some simple maths :
  0.75 x 2 = 0x30 x 0x80 = 0x1800 (0b1100000000000)
Note the word growth, which means we need a longer word length for the partial result. We now need to scale this back to give us our 8 bit result (or we could keep this extended format if this is part of a multiply accumulate (MAC) instruction).
Scaling (right shifting) by the number of fractional bits (6) gives us 0b1100000 (0x60) or 1.5, which is the result we would expect.
We could now perform the same multiply operation with :
  1.5 x 0.5 = 0x60 x 0x20 = 0xC00 (0b110000000000)
And again, if we perform the required scaling by 6 bits we get 0b110000 (0x30) = 0.75
We can see from this example that it is possible to handle numbers with both integer and fractional components using the Q format.

FIR Filtering
  When implementing a regular FIR filter where |h(n)| <= 1.0 then the Q format number system allows for word growth in the accumulator.
  The worst case word growth allows 2^N MAC operations before overflow, where N is the number of guard bits in the accumulator word.
  Using Q format numbers allows m integer bits to be used for the guard bits hence in the above example we can implement 2^2 = 4 MAC operations and guarantee no overflow.
  In more realistic FIR filters where only the central coefficients tend towards the maximum it is possible to implement larger filters before experiencing overflow but these scenarios should always be tested thoroughly.

IIR Filtering
  Unlike FIR filters, where |h(n)| is typically <= 1.0, in IIR filters the coefficient magnitude can often be > 1.0. Here are the coefficients of a very simple 2nd order Low Pass Butterworth Filter :
  float CoefficientArray [] =
  {
    9.57767909330728970000e-002, 1.61076720320250940000e-001, 9.57767909330728970000e-002,
    -1.26453884117041130000e+000, 6.17169143356808060000e-001
  };
  Implementing a filter like this in a fixed point DSP is clearly much more easy when using Q format numbers than either integer or fractional fixed point numbers.

As an example of where you might use Q format numbers is in high quality (>= 24 bit) audio. Using a 32 bit word length allows several options for the values of m and n, for example :
  32 bit word using m.n = 8.24 gives
    8 integer bits for word growth and 24 fractional bits
  32 bit word using m.n = 5.27 gives
    5 integer bits for word growth and 27 fractional bits for fractional bit growth
In these examples it is common to use a 64 bit result / accumulator register then this partial result is converted back to 32 bit Q format for further processing stages.

Please see this blog entry for C code for implementing the Q format number system : http://realgonegeek.blogspot.co.uk/2015/01/c-code-to-implement-q-format-number.html.

Further fixed point references are available at :
    https://www.xmos.com/support/appnotes
    https://github.com/xcore?query=DSP
    http://www.numerix-dsp.com/appsnotes/

This topic is covered in much more detail on the University of Oxford DSP course : http://realgonegeek.blogspot.co.uk/2014/12/the-next-round-of-university-of-oxford.html.

If you have found this solution useful then please do hit the Google (+1) button so that others may be able to find it as well.

Numerix-DSP Libraries : http://www.numerix-dsp.com/eval/

Copyright © 2015 Delta Numerix

Monday, 29 December 2014

Upgraded Version of Digital Filter Plus Supports Q Format Fixed Point Numbers And Apple Mac OS X

The Digital Filter Plus filter design package has now been upgraded to support Q format fixed point number systems upto 64 bits long.
Digital Filter Plus is now also compiled for Apple Mac OS X.
Digital Filter Plus can be downloaded from here : http://www.numerix-dsp.com/dfplus/.
A free version for evaluation and non-commercial applications can be downloaded from here : http://www.numerix-dsp.com/free/.

If you have found this solution useful then please do hit the Google (+1) button so that others may be able to find it as well.

Numerix-DSP Libraries : http://www.numerix-dsp.com/eval/

Copyright © 2014 Delta Numerix

Saturday, 25 October 2014

Building wxWidgets for Windows

I'm a big fan of wxWidgets (http://wxwidgets.org/) and have used it since its earliest days.

With the release of v3.x I have thought I would update many of the programs I have written over the years to be compatible with this version. The update process has been remarkably painless.

Here is how I build wxWidgets and applications to run under it.


Download wxWidgets-3.0.2.zip from : http://sourceforge.net/projects/wxwindows/files/3.0.2/
Extract to : C:\wxWidgets-3.0.2

Download Bakefile v0.2.9 from : https://github.com/vslavik/bakefile/releases

In : C:\wxWidgets-3.0.2\build\msw\
nmake -f makefile.vc BUILD=release clean
nmake -f makefile.vc RUNTIME_LIBS=static BUILD=release

I almost always use "RUNTIME_LIBS=static" because it saves having to include dlls with the application.

Set the WXWIN environment variable :
WXWIN=C:\wxWidgets-3.0.2

Open a command window in : C:\wxWidgets-3.0.2\samples\ - e.g. animate (C:\wxWidgets-3.0.2\samples\animate\)
nmake -f makefile.vc RUNTIME_LIBS=static BUILD=release
cd vc_mswud
anitest

Occasionally I will use the following for debugging but it is not very often because I still haven't found a better solution than printf (or fprintf for logging to a file) :
nmake -f makefile.vc RUNTIME_LIBS=static BUILD=debug

If you have found this solution useful then please do hit the Google (+1) button so that others may be able to find it as well.

Numerix-DSP Libraries : http://www.numerix-dsp.com/eval/

Copyright © 2014 Delta Numerix

Tuesday, 9 September 2014

Controlling an AVB network from a Raspberry Pi

I’ve been playing with Audio Video Bridging (https://www.xmos.com/applications/avb) quite a bit lately and historically I’ve always used the AVDECC-Lib controller (https://github.com/audioscience/avdecc-lib) running on my laptop, either under Windows or Linux.

My intention is to create a completely standalone demo so I’ve since compiled the AVDECC-Lib controller for my Raspberry Pi.

The first thing to do is ensure that the GCC compiler is v4.7 :

sudo apt-get install g++-4.7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6 
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7 
sudo update-alternatives --config gcc

Next we need to ensure that we have all of the required applications and modules :

sudo apt-get install cmake
sudo apt-get install git
sudo apt-get install libpcap-dev
sudo apt-get install libreadline-dev

Now we clone AVDECC-Lib from github :

git clone git://github.com/audioscience/avdecc-lib --recursive

Finally we build the library and application :

cd avdecc-lib
cmake .
make

Now we can run the controller and manage our AVB network :

sudo controller/app/cmdline/avdecccmdline

Note, it is necessary to use sudo because the application requires direct access to the Ethernet PHY.
The controller will now give you a list of network interfaces and you need to choose the appropriate one (2).

AVDECC Controller version: v0.4.9
1 (lo, address: <127.0.0.1>)
2 (eth0, address: <192.168.128.180>)
Enter the interface number (1-2): 2

That’s it, we are now at the controller command line :

Enter "help" for a list of valid commands.
$

If you have found this solution useful then please do hit the Google (+1) button so that others may be able to find it as well.

Numerix-DSP Libraries : http://www.numerix-dsp.com/eval/

Copyright © 2014 Delta Numerix

Tuesday, 24 June 2014

New Co-Presenter on the University Of Oxford DSP Course

With the retirement of my previous co-presenter, Will, I have been searching for a suitably experienced FPGA / DSP designer to replace him. I am pleased to have Volker Mauer join and he will be bringing his many years of experience at Altera to the classes.

A limited number of spaces are still available on the July course : http://www.conted.ox.ac.uk/courses/details.php?id=H600-24

If you have found this solution useful then please do hit the Google (+1) button so that others may be able to find it as well.

Numerix-DSP Libraries : http://www.numerix-dsp.com/eval/

Copyright © 2014 Delta Numerix

Tuesday, 3 June 2014

Gnuplot Installation Under Windows, Linux and MacOS - Solution

Judging by the number of people asking on the forums, this a very common FAQ.

Download and install Gnuplot from http://www.gnuplot.info/download.html.
Ensure that the Gnuplot binary folder is registered in the PATH environment variable so that you can call the Gnuplot executable from any folder.


You may find that Gnuplot reports that the wxt is an unknown terminal type; in which case, use the following command :

Uninstall your current version of Gnuplot and then install the +wxt variant.
port variants gnuplot to list available variants.
sudo port install gnuplot +wxwidgets


Note, after this I had to reboot MacOS to enable Gnuplot to recognize the new terminal types.

Under Linux you need to install both Gnuplot and Gnuplot-X11 :

sudo apt-get install gnuplot
sudo apt-get install gnuplot-x11

If you wish to interface to Gnuplot from a C/C++ application then the Gnuplot/C wrapper could be the answer to your search : https://sourceforge.net/projects/gnuplotc/.

If you have found this solution useful then please do hit the Google (+1) button so that others may be able to find it as well.

Numerix-DSP Libraries : http://www.numerix-dsp.com/eval/

Copyright © 2014 Delta Numerix