Daily Archives: June 10, 2010

Simple RLC meter (Fourier transform part 3)

As an application of the FFT algorithms I present here a simple RLC meter that is able to measure resistors, inductors, capacitors with a reasonable precision. It uses a simple circuit in which a known frequency is sent to a R+Z circuit (where Z could be R, L, C) and then the current and voltage on the Z are measured. The current is indirectly measured by actually measuring the voltage on R.

A PC sound card is used to output the test signal on line-out and also to do acquisition of the measurement signals through line-in.

Two frequencies are used, a low one and a high one for cases where Z is too low or to high.

A calibration is performed with DUT (Device Under Test) unplugged. It will measure the impedance of the circuit and use it subsequently to adjust the DUT measurement.

The time domain signals acquired from the sound card are transformed into frequency domain using FFT and so they become complex signals. Then you could do calculus using DC current methods.

Impedance calculation:

u_L[N] – time domain channel left

u_R[N] – time domain channel right

U_L[N] – frequency domain channel left

U_R[N] – frequency domain channel right

Z = R\frac{U_L}{U_R - U_L}

During calibration the program stores Z_{calib} and then on the DUT measurement it will calculate correct impedance with:

Z_{DUT} = \frac{Z_{mes}Z_{calib}}{Z_{calib} - Z_{mes}}

Note on frequency domain:

FFT will use a number of N points for its calculation which corresponds to maximum frequency of the signal, N/2 corresponds to Nyquist frequency. Therefore if the signal has frequency f you could calculate which point corresponds to this frequency:

k = f \frac{N}{r}, where r is the sampling rate.

Going from complex to real:

\mid Z \mid = \sqrt{Re(Z(k))^2 + Im(Z(k))^2} and

tg(\phi) = \frac{Im(Z(k))}{Re(Z(k))}

Now you could determine whether the DUT is R, L, C based on tg(\phi).

The program runs on Linux with ALSA, alsa-utils, fftw installed.

Source code is distributed under GNU GPL public license and can be downloaded from RLC meter source code.

Fourier transform and signal processing (part 2)

As I told last time, I’m going to present a small project I’ve done to exercise sound card use on Linux,¬† sound processing with Fourier transform, Discrete Fourier Transform(DFT) and Fast Fourier Transform (FFT). All of these are used to make a practical LRC-meter able to measure inductors, resistors, capacitors.

The math behind:

It is not the idea of this article to present the full math theory behind Fourier transform but only to present the application of the theory. Good books that present theory in detail are on the market, e.g. “Discrete-time signal processing” by Oppenheim and Schafer.

Suppose we have a discrete signal represented as x[n] for -\infty < n  < \infty

The Fourier representation of the x[n] is a function of the form:

X(e^{j\omega})=\sum_{n=-\infty}^{n=\infty}x[n]e^{-j\omega n}

The above formula is an analysis formula.

The inverse Fourier transform (which is an synthesis formula) is like this:

x[n] = \frac{1}{2\pi}X(e^{j\omega})e^{j\omega n}d\omega

A Fourier transform translates the signal from time domain to frequency domain in which it represents the signal as a superposition of sine waves each having a coeficient given by the Fourier transform.

Now to make a long story short, a LTI (Linear  Time Invariant) system could be analised by using the Fourier transform. The relationship between the Fourier transform of a signal and the characteristics of the system could be explained as follows:

For LTI system: y[n] = \sum_{k=-\infty}^{\infty}h[n-k]x[k] where h[k] is the impulse response of the system to unit step.

If we choose x[n] = e^{j\omega n} then y[n] = e^{j\omega n}(\sum_{k=-\infty}^{\infty}h[k]e^{-j\omega k})

If we define: H(e^{j\omega}) = \sum_{k=-\infty}^{\infty}h[k]e^{-j\omega k}

then we have y[n] = H(e^{j\omega})e^{j\omega n}

H(e^{j\omega}) – frequency response of the system

Comparing the latest formula with the Fourier transform formula we could see that:

X(e^{j\omega}) = H(e^{j\omega}) meaning that the frequency response of a LTI system is the Fourier transform of impulse response.

The above equality is very important to practical needs just because if you have the frequency response of a LTI system then you could calculate the response to unit step by using the inverse Fourier transform:

h[n] = \frac{1}{2\pi}\int_{-\pi}^{\pi}X(e^{j\omega})e^{j\omega n}d\omega

Discrete Fourier Transform (DCT):

The Fourier transform formula of a discrete signal gives a continue function. Depending on the signal, the sum could be calculated easily or not because of the infinite number of harmonics taken into consideration.

If we consider the signal is periodic with period N so that x[n] = x[n + rN] then we could take into consideration a finite number of samples for X(e^{j\omega})

The Fourier representation in this case is a superposition of complex exponentials with frequencies that are multiple of fundamental frequency \frac{2\pi}{N}.

Therefore DFT will use two formulas:

Analysis equation: X[k] = \sum_{n=0}^{N-1}x[n]W_N^{kn}

Synthesis equation: x[n] = \frac{1}{N}\sum_{k=0}^{N-1}X[k]W_N^{-kn}

whre W_N = e^{-j(2\pi/N)}

Therefore, one could calculate direct/inverse DFT series easily by using a finite length N vector of x[n] respective X[k].

Fast Fourier Transform (FFT):

To calculate DFT with equations above you’ll have complexity O(N^2). It is called FFT, the algorithms that strives to calculate DFT efficiently other than doing the sums above. There are couple such algorithms variations that goes to a complexity of O(Nlog(N)).