dsPIC Audio Filter (Part 2) by Leon Heller G1HSM

Part 1 Dealt with the filter hardware, we now come to the software.

There are two basic types of filter that may be implemented using DSP techniques – the Infinite Impulse Response (IIR) filter and the Finite Impulse Response (FIR) filter. The IIR filter is similar to the analogue filters that you are probably familiar with, built from capacitors, inductors and crystals and rejoicing in such names as Butterworth and Chebyshev. FIR filters do not have any counterpart in the analogue world, as they depend upon being able to store samples in memory. IIR filters use  a lot less memory than the FIR variety, but have several disadvantages such as phase response and possible instability. FIR filter have a linear phase response for all frequencies, and don’t have any stability problems. I’ll be discussing the design of an FIR filter from now on.

As mentioned in Part 1, the audio signal is sampled at a constant rate. With an FIR filter implemented on a DSP, each sample is placed in a circular buffer – a memory array that wraps round, so that it always contains the last, say, 256 samples. A similarly sized circular buffer contains a table of filter coefficients and an operation called convolution is performed – each sample is multiplied by a table entry and a running total is computed by a multiply and accumulate or MAC operation. The result is then output to the DAC. The number of samples in the buffer is often referred to as the number of taps, and you will often see a filter referred to by the number of taps, e.g. a 256 tap filter.

The sharpness of the filter depends on the number of taps, and designing a filter is always a compromise between the number of taps, the amount of available memory, and the processing speed: each convolution operation has to be performed before the next sample arrives. DSPs  have special MAC hardware that performs the operation of multiplying and adding in one clock cycle.

Calculating the filter coefficients involves a lot of maths, and is very time-consuming – just the job for a computer. There are lots of programs available, some of them are free. I use the filter design software sold by Microchip for use with the dsPIC. To design an 800 Hz CW filter I select FIR and the bandpass filter type. I then input the filter specification: sampling frequency, passband frequencies, stopband frequencies, passband and stopband ripple. Here is the frequency response for our 128 tap CW filter:

It’s a pretty good filter, and would be next to impossible to implement using analogue techniques as too many stages would be needed to get equivalent performance.

One can then get the program to output an assembler file containing the filter coefficients that may be linked in with the main program.

The actual DSP part of the main program is quite straightforward – after the buffers are set up all the work is done by one function call in the DSP library:

. FIR(FILTER_BLOCK_LENGTH, &FiltOut[0], &SigIn[0], & bpFilter);

This calls a highly-optimised assembly language routine.
Most of the hard work is getting the codec to do its thing, they are complicated chips with a large number of registers and everything has to be exactly right or nothing works.
If you have internet access, some filtering programs for my hardware may be found in the Files area of the Radio dsPIC Yahoo group that I formed when I started playing with dsPICs:

http://tech.groups.yahoo.com/group/radio_dspic/

My initial test program for my hardware was very simple, it just took the input samples from the codec and sent them immediately to the output. It’s called mic2out and may be found with the other files. Some fun may be had with simple programs like that without doing any actual signal processing. For instance, I once wrote a program for another system that reversed the input samples.

I had a small batch of PCBs made. They have all gone but I could get another batch made if there is enough interest, they weren’t very expensive. I actually made the prototype at home which was quite easy as it’s a single-sided board.

Leon Heller (G1HSM) July 2007.

Return to the index of Vital Spark articles.

G3MGQ’s Month on the Air

Prepared by the clubs RSGB trainer, G3MGQ, you will find the latest DX contests including the ones to shoot for as well as ones to give a wide berth. Why not download the latest edition of Month on the Air and enjoy your DX just that little bit more.

Become a member of HERC

Join the Hastings Electronics and Radio Club.

Why not join one of the largest and most established Radio clubs in the South East of England? Very low joining cost, and free for a year to new licencees.

Vital Spark Archive

Vital Spark newsletter articles

Take a look through a large selection of articles written by club members over the years which have been published in the monthly Vital Spark newsletter .

Used Ham Radio Equipment

View HERC's Used Ham Radio Equipment for sale list..

Every four weeks, HERC's Used Ham Radio Equipment for sale list is updated on the site. Bookmark the gear for sale page to re-visit easily and take advantage of the used equipment on sale through the club.

Club Photographs

HERC Image Galleries.

Here is the official HERC photograph archive which contains multiple image galleries spanning several decades since the club was formed many years ago. Enjoy the images!

UK Amateur Radio Repeaters

UK repeaters

Click button above for full list, or a local repeater callsign below for info.

GB3EB 2m in Uckfield- Active
MB6EB 2m DStar Node in Eastbourne - Active
MB6RY Wires-X DigiGate in Broad Oak - Active
GB3HE 70cm in Hastings - Active
GB7HE 70cm DStar in Hastings - Coming soon
GB3ZX 70cm in Eastbourne - Low Power
GB3JT 23cm ATV in Hastings - NoV cleared
GB7RY 70cm X-Wires Repeater Rye - Active
GB7ES Eastbourne - DSTAR Rpt. - Active
GB3ES 2m in Hastings - Active

For a complete list of repeaters, head over to
the UK Amateur Radio repeaters list.

Popular pages

Get your amateur radio licence - Find out more about amateur radio licence training.
Month on the Air - G3MGQ's popular monthly DX contest/expedition list.
Wilf Gaye Memorial Cup - The clubs annual operating event in the memory of Wilf Gaye M0GYE.
St. Richard's College Buildathon/STEM/ARISS - HERC attends St. Richard's Catholic College for their various events surrounding the Tim Peake ARISS contact.
G3BDQ - John Hey's Rare QSL Cards.
Sussex Electronics Radio Fair - SERF Sussex Electronics Radio Fair 2016.
Vital Spark - A selection of articles re-published from the Vital Spark.
RSGB News - Find out how to get RSGB news on your mobile or PC.
Experimenters Corner - A selection of Proteus projects by Bob Gornal (G7DME)
BBADL - Bath Based Distance Learning Course.
Conquest Hospital Radio - Presented by HERC member Antony (G4CUS).
Radio Rallies 2016 - An up to date list of radio rallies scheduled for 2016.
Club QSL Cards - A selection of QSL cards the club has received over the years.
Other Newsletters - Excellent newsletters and magazines from other clubs.
TX Factor episodes - Take a look at the TX Factors YouTube videos.
John Taplin - A bio of the late John Taplin.

Amateur Radio Resources

Other Radio Clubs & RAYNET

BSARS - Brede Steam Amateur Radio Society

RAYNET - The Hastings and Rother RAYNET Group.

HERC members sites

Sigord - Gordon Sweet
Hastings Radio Comms - Andrew Haas-Campbell
Hoofbags - Liz Costa

Categories