Archive for the ‘DSP’ Category

Open High Definition Video Capture Card

February 21, 2010

Discrete Cosine Transform coefficients

The page I have created for this project over at is here

Here is an excerpt:

This project will capture High Definition Video 1280×720 at 30fps, and hopefully be capable of 60fps and maybe even 1080p. I intend to use a cheap FPGA, A HiSpeed USB PHY, and an Analog Devices Video A/D chip. I will nail down exact chip numbers later. The target platform driver and example code will be written for linux. This project is more a proof of concept and more for fun and excercise rather than to be practical. But I will take any advice and help that I can get and who knows what we might create here. Entire BOM should be less than $40 but we’ll see.

Yes I know about the Hauppage HD-PVR or whatever its called that Capures Component video at 720p. The problem is that device uses H.264 encoding, which is just way too expensive to decode, it takes a Dual Core 1GHz Machine at 99%. It is also not totally open to hacking.

Current Status

  • 04/06/2010 Adding the FPGA to the board now, external devboard is gone.  It will be a spartan3e 250 vq100 pkg.
  • 04/03/2010 Firewire Chip found that offers a High-speed parallel interface, TI TSB12LV32IPZ:
  • 03/25/2010 Mailing List has been added, here is the mailman link to subscribe:
  • 03/24/2010 USB Chip is the USB3250. Working on schematic capture and part selection.
  • 03/19/2010 USB Chip will likely be the USB3250, the USB3318 would be slightly more difficult to put into the UTMI core from opencores.
  • 03/12/2010 Chris has offered to help with the USB portion of the project
  • 03/11/2010 Project now has git hosting on git://
  • 03/11/2010 Added “How To Volunteer” section. Found this core that should work with the USB chip here:,usb
  • 03/09/2010 Created the ad9883a part and package in Eagle. I Began researching what it takes to get the USB3318 chip to work. I am also Considering maybe using the TSB41AB1 1394/Firewire chip. USB is a PITA to work with because of the protocol overhead. If we do Firewire, it will be in addition to USB.

I am in the planning/brainstorming stages, although I have been researching this for at least the last 6-8 months.

I have a working Forward/Reverse DCT algorithm in matlab (actually Gnu Octave) that can compress an image 5:1 with little loss in quality. I have also done much research on putting a DCT in hardware. Currently the DCT will be broken down into 2 stages, and all multiplies/adds will likely be done using a very parallel bit-wide pipeline to keep clock speeds high.

Data Bandwidth Issues
YUV422 720p data comes in at roughly 1280*720*30*16 = 443 MegaBits/s. HiSpeed USB is 480Mbits/s which, after taxes, is probably not enough. Note that 720p60 is twice that. Either way using the DCT and some Huffman coding along with other simple compression techniques we can squeeze the data down a little without hurting quality too bad. My goal is to get it down to 150Mbits/s

BRP-PACU Version 2.0.0 Released Today

December 31, 2008

Its been a while since I posted anything about BRP-PACU, a dual channel FFT based Acoustic Analysis Tool to help engineers configure professional sound systems.  I have been using it regularly, but I recently became motivated to improve it.  Here is a list of improvements obtained from the Changelog.

Screenshot ov BRP-PACU version 2

Screenshot of BRP-PACU version 2

Basically now you don’t need an external pink noise generator or a dual channel capture card.  Just one input should work fine.

Version 2.0.0 Pink Noise and Jack Support (allowing possible Mac OS-X support?)

  • Update on Mac OS-X, my wife’s laptop hasn’t got enough disk space to install macports, xcode, etc, anyone out there who would like to check it out though let me know.
  • Also I need help packaging this for the OS-X and for Linux (deb).

I have a minimal Debian & Xfce based vmware image, which will run on any x86 Mac/Linux/Windows, though.  Not sure how to distribute +850MB of data yet, as ISP’s tend to limit upload bandwidth to a trickle.

Added Pink Noise Output and  the ability to Un/Mute and adjust levels

Added Jack Audio Connection Kit support and removed Alsa (removing need for linux)

  • Automatically connects Reference and Measured inputs to Channel 2 and Channel 1
  • Automatically connects Pink Noise Output to Reference Input and sondcard output
  • This app may now run on a Mac since alsa has been abandoned.  This may require some tweaking.

Major GUI and UI update!

*Delay function now resets delay before each capture, resulting in a much
more intuitive delay finding procedure.

*Rewrote buffer capture interface so that it makes more sense and works

*Rewrote keyboard shortcuts so they don’t interfere with the Avg gain.

*Added default zoom button to return to original zoom settings.

*Added inserted delay size status on the status bar.

*Added “about” and “general help” windows

*TODO: ability to save buffers to a file.  Also a VM for windows and Ubuntu packages.
Miscellaneous Bug Fixes and updates.

Unsolicited Free Audio Advice

June 11, 2008

Attributions For Above Picture

Looking for advice on your next system? No? Too bad. Here it is.

Modern codecs (A/D & D/A converters) are 24 bit 192 kHz and a dime a dozen. You can’t get much better than that as far as noise and dynamic range are concerned. So the most effective place you can spend your money is in an easy to use receiver, the Speakers, and amplifiers. I say easy to use because many receivers are designed by UI buffoons. They are the intersection point of a system and ease of use and setup are at the top of my list.

Tube amplifiers have distortion that is more natural to the human ear. Class A amps are low-power and inefficient, but have the lowest distortion (most linear) if designed correctly. Don’t waste money on over-priced amps marketed with pseudoscience. The little distortion present in most modern amplifers isn’t really enough to fret over. If you think you can hear the difference, there are lots of folks like this guy offering $10K if you can in a blind test. Avoid the snake-oil vendors.

Now for some honest money saving advice and maybe a little toe stepping.

Bose is an interesting manufacturer. They have a well documented history of spending most of their money on marketing and almost none on research. Perfectly legal but I’d rather spend money on quality than marketing. Case in point: the Bose wave radio which is based on research from the 1920’s. It has one narrow resonance band at low frequencies that gives it its “full” sound. I have very little respect for Bose. They have some good stuff here and there, but it all carries the heavy Bose marketing tax.

Don’t waste your money on $700 power cords or expensive power conditioners/surge suppressors. They are pseudoscience BS but perfectly legal, like most of the herb and supplement market, and magnetic bracelets, etc. Nothing is gonna make it through the transformers, buck/boost converters, regulators, and capacitors that you are going to hear. Buy a $20 surge suppressor.

Also on $200 cables. If your system sounds better with one of these cables its probably because it is masking a ground loop that shouldn’t be there in the first place. Eliminate the ground loop first. You shouldn’t have to spend more money on 0-20kHz than the RF engineers spend on 1-2 GHz cable and connectors. This is a blatant ripoff also. Moving any signal in the audio range just doesn’t take that much effort to avoid noise and signal loss. Its actually laughable they get away with it. I could hook up your receiver with a coathanger and you couldn’t hear the difference. Speaker cables are the exact same. Oxygen free is BSt also. Buy something durable that is easy to tidy up.

As far as speakers in the home goes, there are great “practical” speakers that mount in the wall and use the space behind it as an enclosure. These usually sound great and because they use of the wall as a large “invisible” baffle. Speakers are the place you should spend your money. Sound for a home theater is considered “near field” and its actually 10 times easier to accomplish great sound here than filling a large space like a gymnasium or auditorium, where you need high-power drivers with specially designed horns for directivity. There is no need to spend thousands on a set of home speakers. I typically look at the specs (like Xover points, flat frequency response, and decent crossover design) and take a listen to make my decision. JBL’s are well designed, but you pay for that and then some.

I have heard some great chinese knockoffs from distributers like MCM. Here they are so cheap you can buy before you try. If you don’t like them, put them in the garage system. Get a good powered sub and you are set.

The things that can make or break a sound system are ground loops (buzz) caused by incorrect grounding, poor gain structure (distortion and hiss are present), crappy speakers, and an EQ that is incorrect. A good parametric EQ set using a dual channel spectrum analyzer is ideal, but not totally necessary if you choose the right speakers. You can’t set an EQ by listening to it. You can turn up/down the sizzle or the bass to your liking after the system is “flattened” however. Many people put in a “theater curve” by putting in a -3dB/octave dropoff after 2kHz after “flattening”.

I’ve stepped on a few toes, maybe even made an error or two. If you’re angry or dissatisfied with this post I am offering you a full refund. Otherwise feel free to respond with corrections.

BRP-PACU Most Major Update Ever, File Release At Last!

October 9, 2007

File Release!!

For those of you new here, BRP-PACU is an open-source program capable of real-time audio analysis of professionally installed loudspeaker systems. The idea is to use a calibrated microphone to measure the response of a room to playing a reference signal which is usually pink-noise but could be Pink Floyd, as long as it has decent spectral characteristics. The measured signal gets fft’d and divided by the reference signal’s fft. This is captured at 3-5 locations. These captures are then averaged and flipped, then used to calibrate the system.

If none of this rings a bell you probably should read some of my other post topics, because this stuff is probably gonna bore you.

It uses GTK+, alsa-lib, gtkdatabox, fftw, and more! Many of the algorithms were first tested and simulated with Gnu-Octave. Sorry windows users, this requires alsa so tough luck, but you could try it under VMWare, VirtualBox, or Qemu, or even an Ubuntu dual boot.

From my Project News page at

Posted By: electronjunkie
Date: 2007-10-09 12:30
Summary: Current Project Status I have made significant progress now with this project. While it is still not usable in its current state, it does the following:

  • Displays FFT of Blackman Windowed audio input in real-time.
  • Displays the transfer function, H(f) = Y(f) / X(f), of the measured system (channel one divided by channel two, or output (measured) divided by input (reference)), where X(f), Y(f) is the fourier transform of the output and input respectively.
  • GUI now uses the quick excellently documented gtkdatabox library instead of the scantily documented libgoffice. Great Success!
  • Averaging function for the H(f) frame, so graph doesn’t bounce/jump in time and smoothing of the plot to make the data more readable by humans, ex: H(f) = (H(f-1) + H(f) + H(f+1))/3.
  • Impulse Response now works! h(t) = H-1(F)

*Output is in dB and Octaves like humans hear, as opposed to Voltage and frequency in Hz, with actual frequency in Hz displayed under mouse cursor.


  • Add channel 1 & 2 signal indicators
  • Add support for more than the 4 + averaging buffer.
  • Add save as support (so that a session can be saved). This is something even the expensize programs like SMAART do not do. How many times have you sampled a room just to have SMAART or your PC lock up and lose your buffers. It will also allow you to save samples for future reference.

These items are actually trivial to implement. As an engineer all the fft/data related processing is easy to me, the hard part has been the programming read tape (fixing Makefiles to include libraries, using the libraries API’s). But I have learned some excellent concepts along the way.

Currently we are using one thread for the gui/fft app and one thread to obtain the audio. I’ll probably separate the gui from the fft thread, so that I may change the audio thread to a callback instead of polling. Right now I just want to make it work, then I will optimize the coding later.

The code will be released at version 1.0, as it will not be released until I have tested for memory leaks, and actually used it to calibrate a sound system. RT60, and other measurement features will be available in later version releases.


August 31, 2007

Update! fixed link that sourceforge somehow broke.


Brian’s Reasonably Priced Professional Audio Configuration Utility

Audio Engineering With Linux Part II

BRP-PACU in action capturing noise.

File Release today! The code is GPL. To all you MS windows folks out there this means the program is free as in it costs $0. It is also free to use, distribute or even sell, but the source code must be included (upon request) and it must retain the GPL license. Contact your lawyer for more details on legal redistribution.

Un/fortunately it will not run under MS Windows, unless someone decides to modify my code to do so. I may decide to distribute a Linux VMWare player image so that MS Windows folks can use it. There won’t be a huge quantity demand for this software, but those that have a use for it will be desparate enough to use a virtual machine. If someone would like to donate money I will port it to MS Windows. Make me an offer.

Here is a brief description of the project:

Currently there is only overpriced Live Acoustical Analysis ($600-$1200) software capable of performing the transfer function of FFT’s for sound system configuration. This is ridiculous considering the trivial nature of the concepts, but understandable since there is only a limited audience. There does not seem to be an Open Source Version available. And there definitely is no software available under Linux.

This project is written for engineers who configure professional audio systems. It’s main feature will be the ability to take multiple sample transfer function plots (output FFT / input FFT), average them together, and flip the averaged plot to aid in final equalization. Nearly all Professional Audio Engineers use this function now rather than the older Real Time Analysis method because it is quicker and just as precise. This technique is powerful and quick, but very difficult to master, perform properly, and requires a special microphone and mixer to do correctly.

This project will also be able to provide a simple FFT plot to aid in finding room modes and quick audio verification.

This Project uses the FFTW package, libgtkdatabox, GTK+, alsa, and is programmed in C, and runs under Linux.

I currently have a dual threaded program, one which collects audio data, and one that performs the FFT and plots the results. It currently is a full featured audio analysis tool capable of finding the delay automatically in a system and is able to find both the transfer function and the impulse response of an audio system.

Sigma-Delta Modulation Primer Part II

June 30, 2007

UPDATE! Code now bypasses so16() function which would have caused errors for you.

Well here is the first order Sigma-Delta Modulation code for matlab or octave . You will need to download the wav file, or use one of your own that has audio near 16kHz sample rate, and has audio between the first 2000 and 10000 samples. I cannot currently post wav files because wordpress will not let me. If you don’t want to mess with wav’s then you can use the square wave version.

Click For Larger View:
Sigma-Delta Modulation

Go to: Right click on the Space Ghost clip (whatsup.wav) file and do a save as to the same directory as the code. I would provide a direct link but they don’t seem to allow hotlinking.

Here is the first order SDM code for a wav file (GNU Octave):

Created with Vim 7.0 command :TOhtml
%    firstOrderDSM.m
%    Implements a first order Sigma-Delta Modulator
%    Copyright 2007 Brian R Phelps
%    This program is free software; you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation; either version 3 of the License, or
%    (at your option) any later version.
%    This program is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    GNU General Public License for more details.
%    You should have received a copy of the GNU General Public License
%    along with this program.  If not, see;

OSR=10;         % The over sampling rate
z1km1q = 0; % Initialize variables
z1km1 = 0;
% Scale the data to 16 bit "integers", hardware 
% in real life is integer or fixed point math
%returns scaled integers
for n=1:NumSamps
   for k=1:OSR  % Each sample is Oversampled OSR times
      % please see the diagram for an explanation for the following:
      z1(k) = z1km1;
      z1km1 = z1(k) + xn  - z1km1q;
      z1km1q = (z1km1 > 0) * 32766 - (z1km1 <= 0) * 32766;
      y(k+(n-1)*OSR) = (z1km1 > 0) - (z1km1 <= 0);

b=fir1(121,1/(OSR*2));  % A low pass filter is also an integrator (summer), 
                        % either way it is neccessary to recover the original signal
y=filter(b,1,y);        % This gets rid of the noise, which 
                        % most of which is moved out of the passband
y=decimate(y,OSR);      % Keep only 1/10 samples to get the 
                        % sample rate back down to original
plot(1:length(y),y );

Sigma-Delta Modulation Primer Part I

June 24, 2007

Also known as Delta-Sigma modulation. Ever wonder how most sound cards and DACs and even many ADC’s work? The higher quality ones use Sigma Delta Modulation. The theory behind this algorithm is that you can approximate an analog waveform using just a one bit output, and an integrator (Low Pass Filter). This is similar to the way PWM works, but is actually capable of much better resolution for a given set of hardware constraints. Higher order SDM’s require multiplication and addition, which makes the hardware more expensive than a simple PWM. See Figure1 for a low order SDM:

A 1st order noise shaper

This is a first order DSM. It uses an integrator to do noise-shaping and feedback to approximate the input. Basically it tries to match the output y[n] with the input x[n] by oversampling. The higher the oversampling rate, the higher the Signal to Noise ratio (SNR). A typical 4th order DSM can achieve nearly 90-100dB SNR if the oversampling rate (OSR) is around 45. So for 44100 kHz audio we would oversample at 1984500 Hz to achieve this SNR. Keep in mind the y[n] must be fed into a low pass filter.

The SDM has two interesting characteristics that make it useful for audio:

1. It has a dynamic range that is basically only limited by OSR.

2. It works on Digital PCM (sampled) streams or analog data.

Think of it as a guesser that can either output y[n] as a +1 or -1. The +1 or -1 is fed into an integrator many times faster than samples are arriving depending on the OSR. The integrator can be thought of as a summing device, in reality it is a low pass filter. Say your input sample is a 2 and the OSR is 5.

(Previous Value)+1+1-1+1-1+1=2

The next sample is a 1 so:

(PV = 2)-1+1-1+1-1=1

I also used used a friends account at a university to model a 4th order SDM with an OSR of 45. Octave does not yet model SDM’s, but it obviously simulates them if you write the code. Modeling Sigma-Delta Modulators is difficult and involves some control system theory. Basically higher order SDM’s run into stability issues. Again, modeling is more complicated than simulation and implementation, which is what these articles focus on

I have some matlab/octave code that does a 1st order SDM on a wav file. I will post some of my code later in another post. I will post the block diagram for this soon on a follow up. The 4th order model and code/coefficients will also be included.

Audio Engineering With Linux

June 24, 2007


This project will use the alsasound (audio), libgoffice which is used by gnumeric (plots), and the fftw (fast-fourier transform analysis). This project will use these three libraries and gtk (for the gui). There are many different ways to perform this task, I chose these packages because of my experience with all of them. I am using the M-Audio Mobile Pre USB for audio I/O. Laptop soundcards stunk and typically only have one input, but if used properly, it may be possible to do this project with one input.


I am a Linux user. I use Ubuntu 6.10. I have tried other Linux distros and I currently run several. But my main laptop, is Ubuntu. This is a problem/challenge to the real world and the workplace, as most software is written for MS Windows. An example is <an unnamed pricey proprietary software package>, an audio diagnostics tool.

I usually use this pricey proprietary software package to calibrate professional sound systems using its “Transfer Function” feature (output over input). It works very well and is quick to perform, but very difficult to set up and actually perform accurately. The basic idea is that I need to be able to view the output of my sound card divided by the input to it, in the frequency domain usually done using the FFT. I have written a program that takes samples from the mic input, and send data to the line out. I have also used the fftw library to analyze samples. I have even written a few small GTK (a nice gui toolkit) programs. I think I can pull it off, but it will take some time. I am an old school C programmer. I have used many languages such as PHP, Python, Perl, but I always come back to C.

What I am going to do is write a simple GTK based program that allows me to perform the transfer function on a system. It will need to take several samples at different room locations and average them together so that I can use them to calibrate the system. It will need to be able to time-align the frequency data (delay) so that we end up with accurate curves.

Assuming I am not violating any software patents, I will release the project under the GPL on sourceforge. I have looked for a similar open-source project but it doesn’t seem to exist yet.

As I always do for any design, I will Sketch it out Before Coding™. This helps me avoid a complete rewrite midway through the coding.