Wednesday, November 5, 2014

Phase Delay and Group Delay


One benefit of having used OneNote for around a year is that it can be referenced pretty easily for blog post ideas.  Today I'll be writing about phase and group delay through filters

I was looking into making a fractional delay filter at work the other day, and thought it was useful to have some pictures about what phase delay and group delay was.

Wikipedia defines phase delay as the time delay of the phase, where group delay is the time delay of the amplitude envelope.

A nearby textbook defines it as the difference in phase, at a particular frequency,  between an input sinusoidal and the output sinusoidal.

Make sense? Eh. Maybe. Let's make it more complicated before looking at pictures

In FIR filters, group / phase delay is a function of the sampling time and the number of taps:

   group delay = (S-1)*ts/2, where S is the number of taps

Group Delay is also the negative derivative of the phase delay

Let's look at an example:
    I've created a filter in Octave with the signal processing package, coeff=fir1(42,.5).  The frequency response is as follows:


Frequency Response



Paying attention to the phase response, we see it is linear.  An FIR filter if I've ever seen one!

So if I create a 15MHz sine wave sampled at 100MHz........with a ts of 1/100e6=0.01us


Input 15MHz @ 100MHz sampling

Based on the phase response above, 15MHz/50MHz=.3, and at .3 on the phase response gives a 1000 degree phase delay at 15MHz.   


Signal Output

Looking at this picture, we see that there is now ~21 sample delay from the first peak of the input signal to the peak of the output signal, or relative to the output signal, the input signal has processed ~3 360 degree cycles, or ~1000 degrees of phase delay.

Group delay wise, at fractional frequency .4, it looks like we're at ~-1500 degrees. This gives a slope of -3750 degrees per fractional frequency, or -65.43 radians per fractional frequency. Going back to the equation of a line,

           radians = -65.43 (radians / fractional frequency) * (fractional frequency wrt pi radians)

We end up with an extra pi element that needs to be divided out to get rid of radians and scaling for sampling time to get units of time.  This makes the group delay of -(-65.43/3.1415*ts) = .20833us for this filter.  Since the sampling frequency is 100MHz, the sampling time is .01us, a 21 sample delay = .21us.  

This also matches the formula above, of (42-1)*ts/2 giving a group delay of .205us 

Tuesday, October 28, 2014

Installing GNU Octave packages on Mac OSX

I had some issues installing packages for GNU Octave 3.8.0 on OS X Mavericks.  It seems a make file was not setup correctly in the octave folder.

pkg install <package_name> would fail

After searching around for a bit I came across the solution here:

http://lists.gnu.org/archive/html/octave-bug-tracker/2014-02/msg00691.html

The solution is replicated below:


edit /usr/local/octave/3.8.0/bin/mkoctfile-3.8.0 with the following:

> diff mkoctfile-*
53c53,54
< DEFAULT_INCFLAGS="-I$OCTINCLUDEDIR/.. -I$OCTINCLUDEDIR"
---
> #DEFAULT_INCFLAGS="-I$OCTINCLUDEDIR/.. -I$OCTINCLUDEDIR"
> DEFAULT_INCFLAGS="-I$OCTINCLUDEDIR/.. -I$OCTINCLUDEDIR
-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include"


Thursday, October 23, 2014

Ubuntu 14.04 and RTL-SDR

Hello all -

Sorry for the long absence: It is mostly do to me starting to use OneNote to keep all my hard to find information together instead of using this blog.    It is a terrific program for keeping organized digital notebooks, and if you have a Surface Pro or other watcom compatible windows tablet, amazing for handwritten notes.

That aside, I started playing with my USB RTL-SDR with GNURadio again, and was surprised at how much easier it was to setup this time.  Previously I had to compile but the GNURadio and the RTL-SDR drivers myself, but now with Ubuntu 14.04 you can simply

sudo apt-get install gnuradio
sudo apt-get install gnuradio_dev
sudo apt-get install rtl_sdr

These commands will install all required to get started with the DVB-T2 receiver.

I ran into an issue where Ubuntu was autoloading a driver, giving an error when I would try and run an rtlsdr capture:

Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00001096

Using device 0: Generic RTL2832U OEM

Kernel driver is active, or device is claimed by second instance of librtlsdr.
In the first case, please either detach or blacklist the kernel module
(dvb_usb_rtl28xxu), or enable automatic detaching at compile time.

usb_claim_interface error -6
Failed to open rtlsdr device #0.


lsusb showed...
Bus 002 Device 002: ID 8087:8000 Intel Corp. 
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:8008 Intel Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 004: ID 0bda:2838 Realtek Semiconductor Corp. RTL2838 DVB-T
Bus 003 Device 003: ID 0b38:0010 Gear Head 107-Key Keyboard
Bus 003 Device 002: ID 192f:0416 Avago Technologies, Pte. ADNS-5700 Optical Mouse Controller (3-button)
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


dmesg | grep dvb
[ 1326.816881] usb 3-6: dvb_usb_v2: found a 'Realtek RTL2832U reference design' in warm state
[ 1326.873974] usb 3-6: dvb_usb_v2: will pass the complete MPEG2 transport stream to the software demuxer
[ 1326.914525] usb 3-6: dvb_usb_v2: schedule remote query interval to 400 msecs
[ 1326.915830] input: MCE IR Keyboard/Mouse (dvb_usb_rtl28xxu) as /devices/virtual/input/input15
[ 1326.919675] rc rc0: lirc_dev: driver ir-lirc-codec (dvb_usb_rtl28xxu) registered at minor = 0
[ 1326.929266] usb 3-6: dvb_usb_v2: 'Realtek RTL2832U reference design' successfully initialized and connected
[ 1326.929302] usbcore: registered new interface driver dvb_usb_rtl28xxu

The hell!  Get off of my USB stick.  It isn't for you!  Let's temporarily remove it

sudo rmmod dvb_usb_rtl28xxu

Ah, there we go.  Capturing data.  This sequence will unfortunately need to be repeated overtime you plug in the RTLSDR, unless you permanently blacklist it in your mod probe file