signal processing – Cam's Electronics Projects http://localhost Sun, 08 Apr 2018 19:34:46 +0000 en-CA hourly 1 https://wordpress.org/?v=4.7.10 Anti-aliasing filter design part II: filter realization http://localhost/2017/02/21/anti-aliasing-filter-design-part-ii-filter-realization/ Tue, 21 Feb 2017 16:49:49 +0000 http://localhost/?p=43 In my last filter design post, I selected a Chebyshev filter response as the best fit for the bispectrum visualizer. In this post, let’s put some numbers to the response so that we can realize the filter as an electronic circuit.

Finding a design procedure

There are many online calculators and “canned” software packages that give the electronic component values based on a user-supplied filter response. For this project I wanted to work through the design process employed by these programs, but I also didn’t want to spend time deriving the filter response nor re-inventing circuit topologies.

Instead, I found a middle ground by following a paper-and-pencil design procedure presented in Lonnie C. Ludeman’s “Fundamentals of Digital Signal Processing” (1986, Harper & Row Publishers Inc.), specifically in Chapter 3, “Analog Filter Design”.

Follow the procedure

The design procedure starts by putting numbers to the ideal Chebyshev response curve, quoted from page 137 below (included here under fair dealing copyright guidelines):

This curve is shown for a normalized even-order (n) low pass filter whose cut-off frequency is 1 rad/s.

First, I’m going to select the stop frequency to be the Nyquist frequency of the standard CD audio sampling rate of 44.1 kHz, so let Ωr = 22000 * 2π rad/s.

Next, the cut-off frequency (at which the linear gain is equal to 1/(1+ϵ^2)) needs to be selected. The lower the cut-off frequency, the less sharp the transition between the cut-off and stop bands, the lower the filter order, and the simpler the circuit. So this should be set as low as reasonably possible. Even though humans can hear sounds as high as 20 kHz (depending on the person), most commonly encountered sounds exist below 12 kHz as shown by this frequency plot of various common sounds. Why 12 kHz instead of 10 or 14? This is where I’m making an educated guess in balancing the need to capture the desired frequency content against the need to not build an overly complicated filter circuit. So, I selected 12 kHz for the cut-off frequency; this means the 1 rad/s cut-off frequency shown in the above Chebyshev response curve will be scaled to 12000 * 2π rad/s (as per the low-pass to low-pass filter transformation described in Chapter 3 of Ludeman’s textbook cited above).

Now let’s select the maximum passband ripple. The Chebyshev response allows us to have a sharper transition from pass to stop band if we’re willing to accept more passband ripple. In this application, let’s set a maximum 10% reduction in the signal magnitude in the passband; this corresponds to 1 dB of allowable passband ripple. As per the ideal Chebyshev response curve above, the passband ripple is the same as the attenuation at the cut-off frequency. So, by choosing a 1 dB passband ripple, the attenuation at the cut-off frequency will be 1 dB as well.

As for the filter order, let’s select a 4th order filter mainly out of convenience: since many op-amp ICs are two op-amps in one, we can realize two 2nd-order filter stages using one IC.

At this point, all the response parameters are defined except for the stopband attenuation (1/A^2). Based on the equations 3.27 and 3.28 given in chapter 3 of Ludeman’s textbook, one can calculate the required filter order to realize a given set of Chebyshev filter specifications. In our case, we want the filter order to be no larger than n = 4, so instead we’ll calculate the largest stopband attenuation that can be achieved given the rest of the filter parameters. So for a 4th order Chebyshev filter with 1 dB passband ripple, 12 kHz cutoff, and 22 kHz stop frequency, the highest achievable stopband attenuation is 30 dB.

30 dB corresponds to a linear gain of at most 0.032 V/V at 22 kHz (a gain that only decreases as the frequency increases beyond 22 kHz). The ADC on the TIVA LaunchPad has only 12 bits of resolution distributed between 0 and 3.3 V, which means any unwanted signal due to aliasing needs to be attenuated enough to fit within the 0.8 mV quantization step size of the ADC – in other words, unwanted signal with an amplitude of less than 0.4 mV at the ADC input will, for the most part, not be included in the digital representation of the signal. Now the big unknown is the strength of the noise at and above 22 kHz. Though I don’t know how much noise to expect until the circuit is built, with a 30 dB attenuation at the beginning of the stop band, the largest signal voltage that could be more-or-less “hidden” from the ADC, if applied before the filter, would be 12 mV. This will be handy to know to prepare for the possibility of troubleshooting noise problems in the actual circuit.

Selecting a filter topology

We need an active filter topology to realize this Chebyshev filter. Though there are several options available, I’m going to narrow it down to the simplest two options: the Sallen-Key and Multiple Feedback (MFB) topologies. At first, based on this video overview of the two topologies, it seems like Sallen-Key is a good choice since it is less noisy than the MFB. Yet further searching reveals someone’s question regarding the noise properties of the two topologies, and the guy in that video actually answers the question to clarify that the noise gain of the Sallen-Key starts to increase at the “mid frequencies” while the MFB noise gain decreases as frequency increases. This, combined with the fact that the Sallen-Key starts to pass very high frequencies after a certain point, leads me to select the MFB topology for this application.

(Of course, if this were not a hobby project and more were riding on the filter’s performance, I would conduct a more in-depth analysis and perhaps even implement the filter using both topologies and compare the performance, but I believe that would be overkill for what I’m trying to do here.)

Calculating the component values

The MFB topology has one other handy property: its transfer function has the same form as the Chebyshev response transfer function, which basically means that its component values can be calculated such that the resulting electronic filter will have a Chebyshev response. So, we can read the required transfer function coefficients from Tables 3.4 and 3.5 from Ludeman’s analog filter design chapter, and then set these equal to the corresponding coefficients in the MFB topology transfer function. Since the MFB transfer function is written in terms of its component (resistor and capacitor) values, it becomes a matter of resolving a system of equations.

By this point I had put the entire design procedure into a spreadsheet (Filter_Design_4thOrder_MFB_Chebyshev_foronline), and proceeded to determine the component values using guess and check while only “guessing” using values from tables of standard resistor and capacitor values. This way, I can obtain reasonable resistances and capacitances that can be purchased in a single reasonably-sized component.

Simulating the filter

Using Multisim I simulated the resulting two stage filter. In particular, I’m using a unipolar design as I won’t have -3.3 V available to me, so the input signal gets biased to half the supply voltage (half of 3.3 V, or 1.65 V). The 1 F capacitors at the input and output stages will be replaced by a more realistic value when I build the circuit, but for now they are placeholders that won’t affect the simulated low frequency response. Here’s the schematic I drew in Multisim:

The XBP1 component is a virtual instrument that makes Bode plots. Here is the frequency plot generated by XB1 representing the response of the simulated filter (plotted in Octave):

It turns out that, with the selected real-world component values, as well as whatever non-ideal model parameters Multisim takes into account for the 741 op-amp, the response is somewhat less ideal compared to what we would expect from the theoretical Chebyshev response curve. We do get a 1 dB passband ripple, but only up to about 6 kHz, while 6 to 12 kHz sees an additional 2 dB drop, resulting in a cumulative 3 dB attenuation by the time we get to the 12 kHz cut-off frequency. So I ask for a 1 dB passband ripple, but get 3 dB instead. A 3 dB attenuation corresponds to a maximum 29% decrease in signal amplitude. As mentioned in a previous post, passband flatness is not necessary because the bispectrum does not care as much about the relative magnitude of the signals in the passband; for this reason, the cumulative 3 dB attenuation (up to 29% decrease in signal amplitude) at the cut-off frequency (12 kHz) is acceptable for the application. Luckily, the stop band, which starts at 22 kHz, has the 30 dB attenuation I requested. This filter response is adequate for the bispectrum visualizer, so this design step is complete.

]]>
Anti-aliasing filter design part I: filter response http://localhost/2017/01/06/anti-aliasing-filter-design-part-i-filter-response/ Sat, 07 Jan 2017 02:27:46 +0000 http://localhost/?p=22 This post describes the rationale for selecting the magnitude and phase response of the anti-aliasing filter. (The hardware block diagram shows how this filter fits into the overall system.)

Phase response

The phase response of the filter – i.e. the relative time delay applied to each frequency – does not matter as far as the bispectrum is concerned. As I wrote in “A better definition of the bispectrum“, the bispectrum only depends on the relative phase between the signal frequencies f1, f2, and (f1 + f2) when bispectra are averaged and normalized. When the relative phase between these frequency components is constant across the averaged bispectra, the bispectrum is “hot”; when the phase between the components is not constant (i.e. random), it is “cold”. If the original signal is put through a filter prior to the calculation of the bispectrum, each of the frequency components f1, f2, and (f1 + f2) will undergo phase shifts of ϕ1, ϕ2, and ϕ3, respectively; each of these phase shifts will be constant because the bispectrum is independently calculated at every frequency triplet (f1, f2, f1 + f2). So whether the relative phases between frequency components are constant or random in the original signal, adding an unspecified but constant phase shift to each of these frequency components will not affect their phase differences with respect to one another. For this reason, the bispectrum is indifferent to the phase response of the filter. (Within reason of course – if a very long phase delay of 1 second existed in the filter, that would be a problem.)

So the phase response of the anti-aliasing filter need not be flat, despite the bispectrum depending heavily on the phase information present within the signal. Not having a strict requirement on the phase response actually helps us obtain a more desirable magnitude response, as explained in the next section.

Magnitude response

Let’s start with the fundamental response requirement. The anti-aliasing filter should ideally prevent all frequencies in an analog signal that are higher than half the sampling rate from reaching the analog-to-digital converter (ADC). So, we want a low pass type of magnitude response.

Next, let’s choose a particular shape for the low-pass response. I’m going to limit the options to what can be realized with an active filter. Since there will already be a power source in the system, it doesn’t take much additional work to get the benefits of an active filter compared to a passive filter.

This page provides a good introduction to the advantages and disadvantages of the four basic active filter responses. The Bessel, Butterworth, Chebyshev, and Elliptic responses provide progressively steeper roll-off in the transition band. But choosing a response with a steeper roll-off comes at the cost of a less flat phase response as well as progressively greater ripples in the pass and/or stop bands. Since we already know that a flat phase response is not needed, a response with a steeper roll-off can be chosen. Since a steeper roll-off can be achieved, the filter need not have as many components (have as high an order) than if the Bessel or Butterworth responses were used.

The Elliptic response would appear to be a good choice. The Elliptic response, however, has ripples in both the pass and stop bands. I’m willing to accept some ripples in the pass band, only because the bispectrum can probably tolerate some magnitude inaccuracy since the signal magnitude is a secondary determinant of bispectrum magnitude (the primary determinant is the relative phase relationships between frequency components). For the stop band, however, I want uniform attenuation because I don’t want to allow the potential for aliasing at much lower frequencies due to a decrease in stopband attenuation. The Chebyshev filter gives us a flat stopband and an adjustable level of ripple in the pass band. Allowing greater ripple in the pass band allows for a sharper cut-off, so this parameter can be adjusted to permit a trade-off between steepness and passband ripple.

To summarize, an anti-aliasing filter with a Chebyshev response is probably the best fit for the bispectrum visualizer because:

  • It has the sharpest possible roll-off while keeping a flat response in the stopband. This allows me to build a simpler filter with less components.
  • Its passband ripple can be adjusted to strike a balance between the sharpness of the roll-off versus passband ripple.

Next filter design steps

In a sequel post I will define the Chebyshev response parameters, such as passband ripple, cut-off frequency, stop frequency, and stopband attenuation, as well as determine the necessary filter order. In the same post I hope to select an existing electronic filter topology, select the components to obtain the desired response, and simulate the circuit to verify its performance.

]]>
A better definition of the bispectrum (revised Dec 18) http://localhost/2016/12/05/a-better-definition-of-the-bispectrum/ Tue, 06 Dec 2016 02:05:14 +0000 http://localhost/?p=14 In the last entry I wrote about attempting to understand the bispectrum on an intuitive level by building a piece of hardware to display the bispectrum. It turns out, however, that there are some important mathematical aspects of the bispectrum to take into account in order to best design a system that can acquire a signal and display its bispectrum.

In my first post I plotted a bispectrum. The method I used to calculate the bispectrum, while not incorrect, doesn’t do the bispectrum justice. What I had done to make the plot in my last entry was first calculate the discrete fourier transform F(f) of the signal. Then, at each pair of frequency bins (f1, f2), I multiplied only the magnitudes |F(f1)|, |F(f2)|, and |F*(f1 + f2)| and plotted the result. All this really did is create “hot” (red) spots wherever the product of the signal amplitude is large at each of the frequencies f1, f2, and f1 + f2.

Taking into account the phase of the signal

Taking into account the phase information /_F(f), however, really lets the bispectrum shine. To understand this, we need to look at the definition of the bispectrum (from Wikipedia):

B(f1, f2) = F(f1) F(f2) F*(f1 + f2)

If we take a cue from power spectrum estimation techniques and use Welch’s method to estimate the bispectrum by averaging the complex bispectrum calculated from overlapped windowed segments of the signal, then destructive or constructive interference of the bispectral quantity is possible. This means if we apply the averaging implied by Welch’s method, then the frequency pair (f1,f2) will show up as “hot” on the bispectrum plot when the phase of the sinusoids at each of the three frequencies f1, f2, and f1 + f2 add up to the same constant value over all the windowed segements of the signal. A detailed explanation of how the components can sum or cancel is available on Wikipedia’s page for Bicoherence.

Wait… Bicoherence?

It turns out that if you average a bispectrum in the manner I described above and you normalize it, you’ve actually calculated the bicoherence. Ultimately, however, you’re still calculating a bispectrum. To keep things simple, I will continue to use the term bispectrum rather than bicoherence.

I re-did the plot from my last post with this new approach, as shown below. (For those who are interested, there is 50% overlap between windows 1024 samples long, and a Blackman window applied. Normalization is performed by taking the absolute sum of the bispectra divided by the sum of the absolute bispectra.)

This is certainly different from the previous bispectrum. In fact, all of the hot spots on the previous plot are no longer present in the above plot. This alternate method of averaging many bispectra should be used in the firmware of the Bispectrum Visualizer to take advantage of the phase information present in the signal.

]]>
Introduction: What is the bispectrum? http://localhost/2016/11/29/introduction-what-is-the-bispectrum/ Wed, 30 Nov 2016 01:49:37 +0000 http://localhost/?p=5 The bispectrum is a tool for analyzing signals. While the power spectrum of a signal breaks down the power of a signal by its frequency, the bispectrum provides information regarding specific interactions between the various frequency components of a signal. What can this tell us? Various sources, such as Wikipedia, researchers in Japan and the UK, and academic articles say that the bispectrum can tell us about the nonlinear interactions in a process that generates a signal. These are great articles – full of precise mathematics and deep technical detail. But after reading these sources, I don’t understand, on a simple and intuitive level, how the bispectrum of a signal really represents a signal.

Various web searches did not reveal sources with a truly intuitive explanation. Maybe the bispectrum can’t be explained or demonstrated in simple terms at all – math might very well be the only way to communicate the concept. But it looks like no one has really tried to explain what the bispectrum is in a simple manner. I must not be the first person who has faced the bispectrum and felt that the mathematical definition leaves more to be desired. The bispectrum appears to live in an academic world. My goal with this project is to bring the concept of the bispectrum within both conceptual and practical reach of a wider audience.

Show, don’t tell

The mathematical definition of the bispecrtum is like a recipe – it defines the operations necessary to produce a bispectrum. It tells you what to do, and once you do it, you get a result that you can plot, and therefore see. Seeing is essential for understanding. So, I recorded an audio signal of myself saying “hello world” and plotted its bispectrum:

This helps a bit, but not much. What do those vertical and diagonal lines indicate? Is it a unique mark of my voice? What about those green puddles between the lines? I don’t know. It would be better if I had a way of quickly generating the bispectrum of various familiar sounds (signals). In particular, real-time generation of the bispectrum would help me develop an intuitive understanding of how a bispectrum represents sound. Then I might be able to go beyond the mathematical definition by showing what a bispectrum really represents.

Build a bispectrum visualizer

A portable instrument that rapidly and repeatedly computes and displays the bispectrum of real-world sounds would provide the best way, I think, to gain an appreciation of how the bispectrum represents a signal. Spectrum analyzers are commercial laboratory instruments that display the power spectrum of an electrical signal and have been built in the “homebrew” context by electronics hobbyists. So why not build my own bispectrum visualizer? (The name “bispectrum analyzer” is already taken by this software.)

Project goals

To build a standalone device with:

  • A standard audio input connector
  • Signal conditioning circuitry
  • A microprocessor to repeatedly compute the bispectrum of the audio signal reasonably quickly
  • A display to show the bispectrum

Looking ahead

Future posts will cover the system block diagram and circuit topology followed by detailed circuit design and component selection. Stay tuned for more!

]]>