You are on page 1of 39

AMSC

Practical Usage of Fast Fourier


Transform (FFT)

Prepared by: Burak Kelleci

Abstract: This document focuses on practical issues of using the Fourier


Transform for circuit and system design.
AMSC
Document Information

AMSC - Document Information


Document
Owner

Document Burak Kelleci


Contact

Document
Distribution

Document
History

Copyright Copyright  2004


Practical Usage of Fast Fourier
Transform (FFT)

V1.0

11/22/2004

Prepared by:

Burak Kelleci

Abstract: This document focuses on practical issues of using the Fourier


Transform for circuit and system design.
Version Notice

All revisions of this document are listed in chronological order.

Document Release Date Description

v1.0 11/22/2004 Initial release

The draft versions are numbered as v0.x. The release versions are numbered as v1.x.

Trademarks
The trademarks contained in this document are the property of their respective owners.

11/22/2004 ii
Contents

AMSC Document Information ....................................................................................................... ii


Version Notice ................................................................................................................................ ii
Trademarks ................................................................................................................................. ii
Contents ......................................................................................................................................... iii
1 Introduction............................................................................................................................. 1
2 History..................................................................................................................................... 2
2.1 Fourier............................................................................................................................. 3
2.2 Cooley, Tukey and others ............................................................................................... 4
3 Definition of Discrete Fourier Transform (DFT) and its Inverse ........................................... 5
4 Practical Interpretation of Formulas ....................................................................................... 6
5 DFT of a Sine Wave ............................................................................................................... 8
6 Evaluating DFT in Matlab and Cadence................................................................................. 9
7 Non-Integer r......................................................................................................................... 17
8 Aliasing ................................................................................................................................. 20
9 Windowing............................................................................................................................ 22
10 FFT Recipe for Cadence and Matlab ................................................................................ 26
Definitions................................................................................................................................. 26
Transient Analysis Parameters.................................................................................................. 27
Taking FFT in Cadence ............................................................................................................ 27
Taking FFT in Matlab............................................................................................................... 27
Reference ...................................................................................................................................... 29
Appendix....................................................................................................................................... 30
Delta Sigma Modulator............................................................................................................. 30
Bulk-Driven Mixer.................................................................................................................... 32

11/22/2004 iii
Practical Usage of Fast Fourier Transform (FFT)

1 Introduction

Fourier Transform is one of the widely used mathematical tools by the engineers. It reduces the
complex problems, such as spectrum analysis, in a more understandable form. It is almost
impossible to analyze spectrum of any signal without using Fourier transform. Therefore, it is an
essential tool during computer aided design of circuits and systems. However, computer can not
use real numbers; it has to use finite precision numbers due to its digital nature. It is also not
possible to process continuous signals in a computer; all the signals must be discrete. These
requirements can be solved by discrete Fourier transform (DFT). Using the discrete version of
Fourier transform, computer can easily calculate the Fourier transform of any signal. The
calculation speed of DFT is also reduced by Fast Fourier Transform (FFT). This powerful tool
comes with almost all the circuit and system design tools. In this document the examples are
only for Matlab or Cadence. However, the theory is independent of the used tool. The examples
can be transferred to any tool which uses FFT. For example, Spice, Agilent ADS, SystemView,
Hspice, Eldo.

A brief history of Fourier is given in chapter 2. The definitions are presented in chapter 3.
However, these definitions are complex to use during the design. Therefore, a practical version is
presented in chapter 4. The Fourier transform of a sinusoidal signal is calculated in chapter 5.
The methods to calculate DFT in Cadence and Matlab is presented in chapter 6. The most made
error is the selecting the sampling frequency non-integer multiple of input signal. This problem
is explained in chapter 7. Aliasing, in other words downconversion of the signals above the half
of sampling frequency into the band is covered in chapter 8. Windows can be used to improve
the dynamic range. The differences between the windows are explained in chapter 9. Finally, a
practical recipe is presented in chapter 10. Two examples, a delta sigma and mixer, are also
presented in the appendix.

11/22/2004 . 1
Practical Usage of Fast Fourier Transform (FFT)

2 History

Before describing the FFT, a brief history of this mathematical tool and its founders would be in
order. Joseph Fourier developed the basis for the FFT. While James Cooley and John Tukey
developed the FFT algorithm.

Figure 2.1 Jean Baptiste Joseph Fourier

11/22/2004 . 2
Practical Usage of Fast Fourier Transform (FFT)

2.1 Fourier
Born the son of an Auxerre tailor in 1768, Jean Baptiste Joseph Fourier lived to become one of
France's greatest administrators, historians, and mathematicians. He graduated with honors from
the military school in Auxerre, joined the staff of the Ecole Normale and then the Polytechnique
in Paris. He went to Egypt with Napoleon, who made him Governor of Lower Egypt after the
1798 expedition. After returning to France he was made prefect at Grenoble in 1802 and then
baron in 1809, finally ending up as secretary of the Academie des Sciences in 1816 and fellow in
1817. He contributed heavily to Description de l'Egypte, which covered the cultural and
scientific results of Napoleon's invasion of Egypt, issuing 21 volumes over the period from 1808
to 1825. This work led to establishing Egyptology as a recognized new and separate discipline.
Fourier's interest in heat conduction led him to begin work in 1807 on Theorie analytiquede la
chaleur (The Analytic Theory of Heat). Published in 1822, it shows how a mathematical series of
sine and cosine terms can be used to analyze heat conduction in solid bodies. Probably the first
systematic application of a trigonometric series to a problem solution, Fourier spent the rest of
his life working on it and expanding it to include the Fourier integral prior to his death in 1830.
Both the series and the integral allow transformation of physically realizable time-domain
waveforms to the frequency domain and vice versa. Today many areas of study benefit from
Fourier analysis, however the method did not gain acceptability in Fourier's time although
infinite series were in use, most notably Leonard Euler's. The reason behind this was the distrust
of the use of series. One influential mathematician in 1828 commented: "Divergent series are the
invention of the devil, and it is shameful to base on them any demonstration whatsoever". Since
then work by Dirichlet, Friedrich, Riemann, and others have resolved any doubts about the
validity of the Fourier series.
The Fourier transform frequency domain contains the exact same information as that of the
original function, thus, Fourier analysis allows one to examine a function from another point of
view and is used in seemingly unrelated topics from quantum physics to antennas.

11/22/2004 . 3
Practical Usage of Fast Fourier Transform (FFT)

2.2 Cooley, Tukey and others


The major setback in using the transform is computational time. A major tool used in the
analysis, the discrete Fourier transform (DFT) requires extensive computational time to evaluate.
Techniques to reduce the computational time were welcomed in such minimization studies as
that conducted by C. Runge in 1903 which essentially described the FFT. Danielson and Lanczos
in 1942 recognized certain symmetries and periodicities which reduced the number of
operations.
Even with the advent of the digital computer the techniques to reduce computational time were
generally unknown until 1965 when James W. Cooley and John W. Tukey published their
mathematical algorithm which has become known as the fast Fourier transform (FFT).
The advent of this discovery began at a meeting of the President's Scientific Advisory
Committee. Richard L. Garwin, who was in desperate need of a fast means to compute Fourier
transforms for his research with helium, noted that Tukey was writing Fourier Transforms and
asked him to outline his techniques. Garwin then went to the computing center at IBM Research
to have it programmed. Cooley, a relatively new member of the staff, was given the problem
because to his own admission "had nothing important to do" and quickly worked it out. Thinking
he would hear no more about it, Cooley "went back to doing some real work". This was
obviously not the case since Garwin foresaw a wide range of applications and widely publicized
the results. The rest is history--or rather a bit of theory and applications.
.

11/22/2004 . 4
Practical Usage of Fast Fourier Transform (FFT)

3 Definition of Discrete Fourier Transform (DFT)


and its Inverse

The DFT is defined by


N −1
X (k ) = ∑ x(n )e − j 2πkn / N k = 0, L N − 1 (3.1)
n =0

where X (k ) is the kth coefficient of the DFT and x(n ) denotes the nth sample of the time series
which consists of N samples and j = − 1 . The x(n ) 's can be complex numbers and the X (k ) 's
are almost always complex.

There exists the usual inverse of the DFT and, because the form is very similar to that of the
DFT, the FFT may be used to compute it. The inverse of Eqn. (3.1) is

1 N −1
x(n ) = ∑ X (k )e j 2πkn / N n = 0, L N − 1 (3.2)
N k =0
This relationship is called the inverse discrete Fourier Transform (IFFT). It is easy to show that
this inversion is valid by inserting Eqn. (3.1) into Eqn. (3.2)
N −1 N −1
x(n ) = ∑∑ ( x(n ) N )e − j 2πkn / N n = 0,L N − 1 (3.3)
k =0 n =0
Interchanging in Eqn. (3.3) the order of summing over the indices n and k, and using the
orthogonality relation
N −1
− j 2π ( n − m ) / N
∑e
k =0
= N , if n = m mod N
(3.4)
= 0, otherwise
establish that the right side of Eqn.(3.3) is in fact equal to x(n ) .

It is useful to extend the range of definition of X (k ) to all integers (positive and negative).
Within this definition it follows that

X (k ) = X ( N + k ) = X (2 N + k ) = L (3.5)
Similarly,

x(n ) = x( N + n ) = x(2 N + n ) = L (3.6)

11/22/2004 . 5
Practical Usage of Fast Fourier Transform (FFT)

4 Practical Interpretation of Formulas

The primary equation of DFT analysis is the relation,

∆t∆f = 1 N (4.1)
where ∆t is the time difference between two consecutive samples and ∆f is the frequency
resolution. Using Eqn. (4.1) the following important relations are derived,

Maximum Frequency Fmax = N∆f = 1 ∆t = f s (4.2)


Frequency Resolution ∆f = 1 N∆t = 1 Tsim (4.3)
where Tsim is the simulation time. The total sample number should be N. To test whether correct
samples are obtained from a periodic signal, repeat the samples. The new constructed signal
should show same time domain behavior like the original periodic signal. For example, a
sinusoidal signal is sampled (Fig. 4.1). When this signal is repeated, the first sample will be after
the last sample. This new signal will show same time domain behavior like the original
sinusoidal signal.

Sample

Tsim

time
∆t

Figure 4.1 Time Domain Waveform

11/22/2004 . 6
Practical Usage of Fast Fourier Transform (FFT)

Spectrum

0Hz ∆f fs/2-∆f frequency

Figure 4.2 Frequency Domain Waveform

Using Eqns. (4.2) and (4.3) the DFT can be written in the following form
N −1
X (k ) = ∑ x(n )e − j 2πkn (∆t∆f ) k = 0,L N − 1
n =0
N −1
(4.4)
= ∑ x(n )e − j 2πkn / N

n =0

If x(n ) is a real function, the relation

X (k ) = X * ( N − k ) (4.5)
holds, where * indicates complex conjugate. This relation implies that only the first N / 2 values
of X (k ) are unique. Thus, the maximum frequency, Fmax , can be modified to
Fmax (useful) = f s 2 . This is, of course, Nyquist's sampling theorem. Since the first point in the
frequency spectrum represents DC signal, the last point is at fs 2 − ∆f .

11/22/2004 . 7
Practical Usage of Fast Fourier Transform (FFT)

5 DFT of a Sine Wave

Now let's apply the basic formula to the case where the signal is a sine wave.

x(t ) = cos(2πf 0t )
x(n ) = cos(2πf 0 n∆t )
= cos(2π r∆f n∆t ) (5.1)
[
= e j 2πnr∆f∆t
+e − j 2πnr∆f∆t
]/ 2
= [e j 2πnr / N
+ e − j 2πnr / N / 2 ]
where the frequency is chosen in the form f 0 = r∆f , where r is not necessarily an integer.

Substituting x(n ) into Eqn. (3.1),

( )
N −1
X (k ) = ∑ e − j 2πkn / N e j 2πnr∆f∆t + e − j 2πnr∆f∆t / 2
n=0
(5.2)
1 N −1
[
= ∑ e j 2πn (r − k ) / N + e − j 2πn (r + k ) / N
2 n=0
]
Equation (5.2) is a geometric series and can be evaluated in closed form as,

1  e j 2πn (r − k ) − 1 e − j 2πn (rl + k ) − 1 


X (k ) =  +  (5.3)
2  e j 2πn (r − k )∆f∆t / N − 1 e − j 2πn (r + k ) / N − 1
Finally, the power spectra P (k ) = X (k )X * (k ) reduces to simple form;

1  sin 2 (π (r − k )) sin 2 (π (r + k )) 
P (k ) =  +  (5.4)
2  sin 2 (π (r − k ) / N ) sin 2 (π (r + k ) / N ) 
Consider the cases where l is an integer, and r ≠ k . Then P (k ) = 0 since k is an integer also.
When r = k both numerator and denominator are 0, and the limiting result is P (r ) = N 2 2 . Thus,
when r is an integer, the digital spectra produces the intuitive result that P = 0 everywhere
except at the input signal frequency f l = r∆f .

11/22/2004 . 8
Practical Usage of Fast Fourier Transform (FFT)

6 Evaluating DFT in Matlab and Cadence

Matlab and Cadence have built-in fast fourier transform (FFT) routines to calculate signal
spectrum. The main advantage of FFT with respect to DFT is it needs fewer multiplications.
Although DFT requires N 2 complex multiplications, FFT requires only (3 N 8) log 2 ( N ) for
Radix-4 algorithm. For example if N = 16 , DFT requires 256 multiplications, FFT requires only
24 . For higher N numbers the difference increases dramatically. N vs. multiplication number
is shown in Fig. 6.1. The main drawback of FFT is that log 2 (N ) must be an integer number.
Otherwise, DFT must be used to calculate the frequency spectrum. Although Matlab has built-in
DFT routines, Cadence has not built-in DFT. Cadence rounds log 2 (N ) nearest integer and
calculates the sampling frequency using this N value. For example, if 10 samples are obtained
instead of 16, Cadence first rounds up FFT number to 16 and calculate 16 samples using
interpolation. This technique creates harmonics due to the interpolation.
10
10
DFT Complex Multiplication Number
FFT Complex Multiplication Number

8
10
Number of Complex Multiplications

6
10

4
10

2
10

0
10

-2
10
0 1 2 3 4 5
10 10 10 10 10 10
FFT Number

Figure 6.1 FFT size vs. Complex Multiplication Number


FFT outputs covers always negative frequencies as well. The following Matlab code generates
the spectrum of cosine input signal. Although the output power is N 2 / 2 , in most of applications
only amplitude or rms values of the signals are needed. For example, in the following Matlab
code N is selected as 16, therefore, the total power will be 16 2 / 2 = 128 . Since cosine has two
spectral components, the sum of this components power will be 128 . It is clear that
normalization should be performed to get real amplitude levels. Since, negative frequencies are

11/22/2004 . 9
Practical Usage of Fast Fourier Transform (FFT)

complex conjugate of positive frequencies for real signals, obtaining only positive frequencies is
enough. Therefore, the spectrum value of the input signal should be set to signal rms or
amplitude value. Dividing the FFT output by N / 2 gives rms value. However, in most
applications only signal amplitudes are considered. Therefore, the FFT output is multiplied by
2 / N to obtain amplitude of the signal. On the other hand, at DC the power is not separated to
two spectral components. Therefore, the DC component should be multiplied by 1/N.

Most of the time, the frequency resolution and sampling frequency are important parameters for
FFT calculations. The other parameters, such as number of FFT or time and frequency vectors
can be easily calculated from these parameters. FFT number N can be obtained by dividing
sampling frequency by frequency resolution. If negative frequencies are also considered the
frequency vector starts at (− f s / 2 ) and ends at (f s / 2 − df ) . The step should be equal to
frequency resolution. On the other hand the time data starts at 1 / f s and ends at 1 / df . Since the
sampling frequency is f s , the time step should be 1 / f s . The time vector can also starts at 0 ,
however, now it should end at (1 / df − 1 / f s ) , since only N number samples are needed.

Let's examine the output spectrum of a sinusoidal signal. The amplitude is selected as 1 V and
the frequency is selected 2 Hz . The output spectrum is shown in Fig. 6.2. In the spectrum the
signals at input signal frequency are at 2 Hz and − 2 Hz as expected. However, FFT result
shows signals at the other frequencies. These signals amplitudes are 300 dB less than the input
signal frequency. The reason for these signals is that the double number precision. Since all the
numbers in a computer is finite, this causes a numerical noise. Therefore, their spectral density is
flat. If the computer calculates the sampling instants by interpolations, this causes more
numerical noise. Therefore, interpolation should be avoided.

Till now N is assumed an even number. If it is an odd number, the frequency vector changes
slightly. It starts at (− f s / 2 + df / 2 ) instead of (− f s / 2 ) and ends at (f s / 2 ) instead of
(f s / 2 − df ) .

11/22/2004 . 10
Practical Usage of Fast Fourier Transform (FFT)

%Spectrum for negative and positive frequencies


%N is even number
fs=16; %Sampling Frequency
df=1; %Frequency Resolution
N=fs/df; %FFT Number
f=-fs/2:df:fs/2-df; %Frequency Vector
t=1/fs:1/fs:1/df; %Time Vector
x=cos(2*pi*2*t);
w=window(@rectwin,N); %select appropriate window
xw=x.*w';
xf=(N/sum(w))*fft(xw)*2/N;
xfn=fftshift(xf);
xfn((N/2)+1)=xfn((N/2)+1)/2; %Normalize DC
mag_xfn=20*log10(abs(xfn));
phase_xfn=angle(xfn)*180/pi;
phase_xfn=phase_xfn-phase_xfn(N/2+1);
figure(1);
subplot(2,1,1),plot(f,mag_xfn);
subplot(2,1,1),xlabel('Frequency (Hz)');
subplot(2,1,1),ylabel('Magnitude (dB)');
subplot(2,1,1),grid;
subplot(2,1,2),plot(f,phase_xfn);
subplot(2,1,2),xlabel('Frequency (Hz)');
subplot(2,1,2),ylabel('Phase (degrees)');
subplot(2,1,2),grid;
figure(2);
plot(t,x);
xlabel('Time (s)');
ylabel('Input Signal');

11/22/2004 . 11
Practical Usage of Fast Fourier Transform (FFT)

%Spectrum for negative and positive frequencies


%N is odd number
fs=15; %Sampling Frequency
df=1; %Frequency Resolution
N=fs/df; %FFT Number
f=-fs/2+df/2:df:fs/2; %Frequency Vector
t=1/fs:1/fs:1/df; %Time Vector
x=cos(2*pi*2*t);
w=window(@rectwin,N); %select appropriate window
xw=x.*w';
xf=(N/sum(w))*fft(xw)*2/N;
xfn=fftshift(xf);
xfn((N+1)/2)=xfn((N+1)/2)/2; %Normalize DC
mag_xfn=20*log10(abs(xfn));
phase_xfn=angle(xfn)*180/pi;
phase_xfn=phase_xfn-phase_xfn(N/2+1);
figure(1);
subplot(2,1,1),plot(f,mag_xfn);
subplot(2,1,1),xlabel('Frequency (Hz)');
subplot(2,1,1),ylabel('Magnitude (dB)');
subplot(2,1,1),grid;
subplot(2,1,2),plot(f,phase_xfn);
subplot(2,1,2),xlabel('Frequency (Hz)');
subplot(2,1,2),ylabel('Phase (degrees)');
subplot(2,1,2),grid;
figure(2);
plot(t,x);
xlabel('Time (s)');
ylabel('Input Signal');

11/22/2004 . 12
Practical Usage of Fast Fourier Transform (FFT)

-50

-100

Magnitude (dB)
-150

-200

-250

-300

-350
-8 -6 -4 -2 0 2 4 6 8
Frequency (Hz)

300

200
Phase (degrees)

100

-100

-200

-300

-400
-8 -6 -4 -2 0 2 4 6 8
Frequency (Hz)

Figure 6.2 Double Sided Spectrum


The following Matlab code generates only positive spectrum. The output spectrum is shown in
Fig. 6.3.

%Spectrum for positive frequencies


%N is even number
fs=16; %Sampling Frequency
df=1; %Frequency Resolution
N=fs/df; %FFT Number
f=0:df:fs/2-df; %Output Frequency
t=1/fs:1/fs:1/df; %Time Data
x=cos(2*pi*2*t);
w=window(@rectwin,N); %select appropriate window
xw=x.*w';
xf=(N/sum(w))*fft(xw)*2/N;
xfn=xf(1:N/2);
xfn(1)=xfn(1)/2; %Normalize DC
mag_xfn=20*log10(abs(xfn));
phase_xfn=angle(xfn)*180/pi;
phase_xfn=phase_xfn-phase_xfn(1);
figure(1);
subplot(2,1,1),plot(f,mag_xfn);
subplot(2,1,1),xlabel('Frequency (Hz)');
subplot(2,1,1),ylabel('Magnitude (dB)');
subplot(2,1,1),grid;

11/22/2004 . 13
Practical Usage of Fast Fourier Transform (FFT)

subplot(2,1,2),plot(f,phase_xfn);
subplot(2,1,2),xlabel('Frequency (Hz)');
subplot(2,1,2),ylabel('Phase (degrees)');
subplot(2,1,2),grid;
figure(2);
plot(t,x);
xlabel('Time (s)');
ylabel('Input Signal');

%Spectrum for positive frequencies


%N is odd number
fs=15; %Sampling Frequency
df=1; %Frequency Resolution
N=fs/df; %FFT Number
f=0:df:fs/2-df/2; %Output Frequency
t=1/fs:1/fs:1/df; %Time Data
x=cos(2*pi*2*t);
w=window(@rectwin,N); %select appropriate window
xw=x.*w';
xf=(N/sum(w))*fft(xw)*2/N;
xfn=xf(1:(N+1)/2);
xfn(1)=xfn(1)/2; %Normalize DC
mag_xfn=20*log10(abs(xfn));
phase_xfn=angle(xfn)*180/pi;
phase_xfn=phase_xfn-phase_xfn(1);
figure(1);
subplot(2,1,1),plot(f,mag_xfn);
subplot(2,1,1),xlabel('Frequency (Hz)');
subplot(2,1,1),ylabel('Magnitude (dB)');
subplot(2,1,1),grid;
subplot(2,1,2),plot(f,phase_xfn);
subplot(2,1,2),xlabel('Frequency (Hz)');
subplot(2,1,2),ylabel('Phase (degrees)');
subplot(2,1,2),grid;
figure(2);
plot(t,x);
xlabel('Time (s)');
ylabel('Input Signal');

11/22/2004 . 14
Practical Usage of Fast Fourier Transform (FFT)

-50

-100

Magnitude (dB)
-150

-200

-250

-300

-350
0 1 2 3 4 5 6 7
Frequency (Hz)

250

200
Phase (degrees)

150

100

50

-50
0 1 2 3 4 5 6 7
Frequency (Hz)

Figure 6.3 Single Sided Spectrum

This simulation is also repeated in Cadence. Frequency spectrum of a sinusoidal source is shown
in Fig. 6.4. However, the spectrum shows high numerical noise comparing Matlab results. Since
simulator does not calculate at every datapoint, the FFT samples are calculated using
interpolation. This procedure increases numerical noise dramatically. One way to reduce this
noise is tighten the tolerances. This method causes convergence problems. The best method is to
force the simulator to calculate at the FFT sample points. To do this, the strobeperiod parameter
is set to 1 / f s , which is 1 / 16 = 0.0625 in this example. The skipstart parameter is set to 0 , since
the sampling starts at 0 s . The strobedelay is also set to zero, since there is no phase difference
between the first sample point and skipstart. The simulation result is shown in Fig. 6.5. Now
Cadence simulation result is same as the Matlab result. If the signal shows some transient
behavior, the skipstart parameter should be set higher than 0 to take FFT at steady state.

11/22/2004 . 15
Practical Usage of Fast Fourier Transform (FFT)

Figure 6.4 Output Spectrum in Cadence

Figure 6.5 Output Spectrum in Cadence with strobeperiod

11/22/2004 . 16
Practical Usage of Fast Fourier Transform (FFT)

7 Non-Integer r

In the previous chapters the input signal is integer multiple of frequency resolution. However,
especially during measurement of signals, it is not always possible to select the input signal at
the multiple of frequency resolution. In the following example, the sampling frequency is
selected as 16 Hz and frequency resolution is 1 Hz. The input signal is selected at 2.555 Hz,
which is 2.555 times of frequency resolution. The spectrum is shown in Fig. 7.1. The spectrum
seems distorted. Decreasing frequency resolution to 0.01 Hz does not solve the problem. The
input frequency is still non-integer multiple of frequency resolution. Finally, when the input
signal frequency is integer multiple of the frequency resolution, the spectrum is as expected.

-2

-4

-6

-8
Magnitude (dB)

-10

-12

-14

-16

-18

-20
0 1 2 3 4 5 6 7
Frequency (Hz)

Figure 7.1 Output Spectrum (Frequency Resolution = 1Hz)

11/22/2004 . 17
Practical Usage of Fast Fourier Transform (FFT)

-10

-20
Magnitude (dB)

-30

-40

-50

-60
0 1 2 3 4 5 6 7 8
Frequency (Hz)

Figure 7.2 Spectrum (Frequency Resolution = 0.01Hz)

-50

-100
Magnitude (dB)

-150

-200

-250

-300

-350
0 1 2 3 4 5 6 7 8
Frequency (Hz)

Figure 7.3 Output Spectrum (Frequency Resolution = 0.001Hz)

11/22/2004 . 18
Practical Usage of Fast Fourier Transform (FFT)

Now, the question is why spectrum shows some modulation, when the input signal is selected
non-integer multiple of frequency resolution. Although there is no modulation on the signal, the
spectrum is correct. This result can be verified by analytical expression. Figures 7.1 and 7.2
show what is called bin splatter. In digital signal processing books this phenomena is referred as
leakage. Note how slowly the skirts decrease as a function of frequency (actually 1 / f 2 ). To
obtain a physical picture the basic analog Fourier transform is evaluated for the same sine wave.
The spectra is

1  sin 2 (π ( f 0 − f )T )
 sin 2 (π ( f 0 + f )T )
P( f ) = + 2
 2 
((
(7.1)
2  sin (π ( f 0 − f )T / N ) sin π f 0 + f T / N
 ) )
Near f 0 Eq. (7.1) can be simplified using the assumption sin ( x ) ≈ x for small x values.

1  sin (π ( f 0 − f )T ) 
2

P( f ) ≈   (7.2)
2  (π ( f 0 − f )T / N ) 
This expression has maximum at f = f 0 , and the nulls are separated at integer multiples of 1 / T
from this maxima. If P ( f ) is evaluated for discrete frequencies, which are multiples of 1 / T , the
maxima of the peak is sampled, while for any other sample the value is zero. However, when f in
equals 32.5 Hz , the 1 Hz samples intersect the spectrum as shown in Fig. 7.5. This result is
identical to the result in Figs. 7.1 and 7.2.
0 0

-5
-50

-10

-100
-15

-20
Magnitude (dB)

Magnitude (dB)

-150

-25

-200
-30

-250 -35

-40
-300

-45

-350
27 28 29 30 31 32 33 34 35 36 37 -50
Frequency (Hz)
28 29 30 31 32 33 34 35 36 37
Frequency (Hz)

Figure 7.4 Output Spectrum Figure 7.5 Output Spectrum


(Input Frequency = 32 Hz) (Input Frequency = 32.5 Hz)

11/22/2004 . 19
Practical Usage of Fast Fourier Transform (FFT)

8 Aliasing

In previous chapters the signal is assumed band-limited and does not have any spectral
components above fs/2 . However, it is not valid in some applications, such as DAC. The output
of a DAC has abrupt changes, which requires infinite bandwidth. When the FFT of a signal with
inifinite bandwidth is taken, the frequency components higher than fs/2 is downconverted to the
band. For example, the FFT of square wave is shown in Fig. 8.1. The signal frequency is

1.5 Hz, and the frequency resolution is 0.1 Hz. The sampling frequency is selected 16 Hz. Since
square wave need infinite bandwidth, the odd harmonic components above 8 Hz will be
downconverted. The signal frequencies are summarized in Tab. 8.1. To find the frequency of the
downconverted signals, the following formula can be used

f down = n ⋅ f s − f signal n : integer from − ∞ to ∞ (8.1)

50

-50

-100
Magnitude (dB)

-150

-200

-250

-300

-350
0 1 2 3 4 5 6 7 8
Frequency (Hz)

Figure 8.1 Output Spectrum due to Aliasing

11/22/2004 . 20
Practical Usage of Fast Fourier Transform (FFT)

f har f down f har f down

1.5 Hz 0 Hz + 1.5 Hz 1.5 Hz 4.5 Hz 0 Hz + 4.5 Hz 4.5 Hz

7.5 Hz 0 Hz + 7.5 Hz 7.5 Hz 10.5 Hz 16 Hz – 10.5 Hz 5.5 Hz

13.5 Hz 16 Hz – 13.5 Hz 2.5 Hz 16.5 Hz 16.5 Hz – 16 Hz 0.5 Hz

19.5 Hz 19.5 Hz – 16 Hz 3.5 Hz 22.5 Hz 22.5 Hz – 16 Hz 6.5 Hz

Table 8.1 Square Wave Harmonic Components

To reduce the aliasing problem, the signal must be bandlimited before FFT. A low-pass filter
serves very well. However, filtering changes signal phase. To reduce phase delay a low order
filter can be used. However, low order filter may be not enough to suppress high frequency
components. To overcome this problem, sampling frequency should be increased till required
attenuation of signals over fs/2 guaranteed. The drawback of this method is that for the same
frequency resolution higher sampling frequency results in higher simulation time.

Matlab has many built-in filter functions. However, Cadence can simulate only s-domain transfer
functions. To use this property, the component svcvs must be used. This component can be used
to realize any s-domain transfer function. The filter coefficients can be calculated in Matlab, and
entered in svcvs to realize the filter in Cadence.

11/22/2004 . 21
Practical Usage of Fast Fourier Transform (FFT)

9 Windowing

The DFT results can be significantly different than what might be viewed on an analog spectrum
analyzer if the input signal is non-integer multiple of frequency resolution. In this case the signal
can be recovered by applying appropriate window to the data. The well-known window functions
are summarized in Tab. 9.1. The windows are distinguished according to their following
properties, which is shown in Fig. .9.1.

Peak Sidelobe Level: It gives one indication of the dynamic range of the window. That is, how
small can signal be and still be detected in the presence of a large signal and its sidelobes.

Rolloff Rate: This parameter describes the amplitude fall off of sidelobe peaks. This is another
indication of the available dynamic range is the rolloff rate of the window.

3 dB Bandwidth: The resolution of the window, i.e., the ability to distinguish two closely spaced
sinusoids from a single sinusoid, is dictated by the 3 dB Bandwidth.

Coherent Gain: This is a measure of the window that takes into account data sequence weighting
and assumes a sinusoid is centered. The coherent gain GC is given by

1 N −1
GC = ∑ w(n )
N n=0
(9.1)

Window Peak Sidelobe Rolloff Rate 3 dB Bandwidth Coherent Gain


(dB) (dB/oct)

Rectangle -13 -6 0.86/T 1

Hamming -42 -6 1.3/T 0.54

Hanning -47 -30 1.86/T 0.38


(cosine4)

Kaiser ( β = 11 ) -82 -6 1.83/T 0.37

Minimum 4-term -92 -6 1.9/T 0.36


Blackman-Harris

Table 9.1 Window Properties

11/22/2004 . 22
Practical Usage of Fast Fourier Transform (FFT)

Peak Sidelobe
(dB) Rolloff Rate
(dB/oct)
3dB
Bandwidth

Figure 9.1 Window Properties


Comparing the attributes of the windows listed in table, the rectangular window has the smallest
mainlobe width and thus the best spectral resolution. However, the leakage, as indicated by the
peak sidelobe level and rolloff rate, is poor. The mainlobe widths of the other windows are
almost same, and they are distinguished only by their leakage properties. In particular, the
minimum 4-term Blackman-Harris window has the lowest sidelobe level, while the hanning has
the steepest rolloff rate. Kaiser window has a parameter to set its performance. Therefore, by
selecting appropriate β , Kaiser Window can show better performance than the others.

To demonstrate different window performances FFT of a signal with two spectral components is
taken. The frequency resolution is selected 0.1 Hz and sampling frequency is 16 Hz. The spectral
components are at 2 Hz and 2.55 Hz. Although the component at 2 Hz is at integer multiple of
frequency resolution, the other component is not. The power of signal at 2 Hz is 40 dB lower
than the other one. The spectrum with rectangular window is shown in Fig.~\ref{rect}. It is
obvious it is not possible to seperate the signals. Using windowing these signals can be
distinguished. Kaiser and Blackman-Harris windows shows best performances, since their peak
sidelobe is very low. Every window distinguishes the signals, and the calculated levels are also
correct. For example, the blackman window gives 0 dB (1V) for the signal at 2.55 Hz and -40 dB
(0.01V) for the signal at 2 Hz. The peak of 2 Hz signal is not flat, therefore this signal at the
integer multiple of frequency resolution. The peak of the other signal is flat, which shows that
this signal is not integer multiple of frequency resolution.

Kaiser window has a parameter to set the sidelobe height. To achieve a sidelobe height of
− α dB , the β parameter is

11/22/2004 . 23
Practical Usage of Fast Fourier Transform (FFT)

 0.1102(α − 8.7 ) α > 50



β = 0.5842(α − 21) + 0.07886(α − 21) 50 ≤ α ≤ 21
0.4
(9.2)
 0 α < 21

For rule of thumb, β can be selected as 0.11 times required sidelobe height, since most of the
time low sidelobe height is required. For example, to seperate signal which have 40 dB
difference, the sidelobe level must be higher than 40 dB. If it is selected 50 dB, the required β is
5.5. Figure 9.5 shows the result. Since the sidelobe is lower than 40 dB, the signals are seperated.
On the other hand, increasing β increases also the mainlobe width. If the signals are to close, the
weakest signal can be buried in the strongest signal mainlobe. For example, if β is selected 50,
the sidelobe will be 500 dB lower (Due to the double-precision number it is not possible to
observe 500 dB sidelobe). However, any signal 3.2 Hz closer than to the strongest signal will be
buried in the mainlobe of the strongest signal. In this example the weak signal is only 0.55 Hz
away from the strongest signal. The spectrum is shown in Fig. 9.6. If distance between these
signals is increased, so that the weak signal is not in the mainlobe of strong signal, the signals
can be easily seperated. For example, if the weak signal frequency is changed to 6 Hz instead of
2 Hz, the weak signal is not in the mainlobe anymore. The FFT result is shown in Fig. 9.7.

0 0

-5
-10

-10

-20
-15
Magnitude (dB)

Magnitude (dB)

-20 -30

-25
-40

-30

-50
-35

-40 -60
0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8
Frequency (Hz) Frequency (Hz)

Figure 9.2Output Spectrum (Rectangular Figure 9.3 Output Spectrum (Hamming Window)
Window)

11/22/2004 . 24
Practical Usage of Fast Fourier Transform (FFT)

0 0

-10
-50

-20

-100
-30

-40

Magnitude (dB)
Magnitude (dB)

-150

-50

-200
-60

-70 -250

-80
-300
-90

-100 -350
0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8
Frequency (Hz) Frequency (Hz)

Figure 9.4 Output Spectrum (Hanning Window) Figure 9.6 Output Spectrum (Kaiser Window
β = 50 f in = 2.55 and 2 Hz )
0
0

-10

-50

-20

-100
-30
Magnitude (dB)

Magnitude (dB)

-150
-40

-50 -200

-60
-250

-70

-300

-80
0 1 2 3 4 5 6 7 8
Frequency (Hz)
-350
0 1 2 3 4 5 6 7 8
Frequency (Hz)

Figure 9.5 Output Spectrum (Kaiser Window


β = 5 .5 ) Figure 9.7 Output Spectrum (Kaiser Window
β = 50 f in = 2.55 and 6 Hz )

-20

-40
Magnitude (dB)

-60

-80

-100

-120

-140
0 1 2 3 4 5 6 7 8
Frequency (Hz)

Figure 9.8 Output Spectrum (Blackman Window)

11/22/2004 . 25
Practical Usage of Fast Fourier Transform (FFT)

10 FFT Recipe for Cadence and Matlab

Definitions
fs: Sampling Frequency

df: Frequency Resolution

N: FFT Number N = f s /df

Tsim: Simulation Time = 1/df

The output spectrum is between (− f s / 2 ) and (f s / 2 − df ) .

(Cadence plots only from 0 to (f s / 2 ) , since for real signals positive and negative frequency
components have same magnitude response)

The signals and intermodulation products must be integer multiple of frequency resolution.

Signals and intermodulation products must be integer multiple of frequency resolution

Limit the signal bandwidth to avoid aliasing

Take sample points during the steady state

For example:

f1 = 1 GHz and f 2 = 1.1 GHz

The intermodulation products are 100 MHz apart

Maximum frequency resolution is 100 MHz

Minimum simulation time 1 / 100 MHz = 10 ns .

11/22/2004 . 26
Practical Usage of Fast Fourier Transform (FFT)

Transient Analysis Parameters


outputstart: Output is saved only after this time is reached.

skipstart: The time to start skipping output data.

skipstop: The time to stop skipping output data.

strobeperiod: The output strobe interval (in seconds of transient time).

strobedelay: The delay (phase shift) between the skipstart time and the first strobe point.

Taking FFT in Cadence


tsim equals to tstop-tstart.

N must satisfy the following condition N = 2 k (k : integer )

Set strobeperiod, strobedelay and skipstart parameters to force the simulator to calculate at
sampling points.

If possible use PSS analysis to calculate spectrum. PSS will automatically calculate at sample
points.

If possible tighten the tolerances (reltol=1e-6 vabstol=3e-8 iabstol=1e-15 integration method =


gear2only)

Taking FFT in Matlab


N can be any integer number.

Cadence results can be extracted using the following command

ocnPrint( v("/out" ?result "tran") ?output "temp.dat" ?numberNotation 'none)

Clean first lines in temp.dat, the file should starts with numbers.

The following Matlab code can be used to import the simulation data

[t,x]=textread('temp.dat','\%f\%f');

11/22/2004 . 27
Practical Usage of Fast Fourier Transform (FFT)

Sample Matlab Code to calculate FFT

%N is even
fs=16; %Sampling Frequency
df=1; %Frequency Resolution
N=fs/df; %FFT Number
f=0:df:fs/2-df; %Output Frequency
t=1/fs:1/fs:1/df; %Time Data
x=cos(2*pi*2*t); %Input Signal
w=window(@rectwin,N); %select appropriate window
xw=x.*w';
xf=(N/sum(w))*fft(xw)*2/N;
xfn=xf(1:N/2);
xfn(1)=xfn(1)/2; %Normalize DC
mag_xfn=20*log10(abs(xfn));
figure(1);
plot(f,mag_xfn,'k');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
grid;

%N is odd
fs=15; %Sampling Frequency
df=1; %Frequency Resolution
N=fs/df; %FFT Number
f=0:df:fs/2-df/2; %Output Frequency
t=1/fs:1/fs:1/df; %Time Data
x=cos(2*pi*2*t); %Input Signal
w=window(@rectwin,N); %select appropriate window
xw=x.*w';
xf=(N/sum(w))*fft(xw)*2/N;
xfn=xf(1:(N+1)/2);
xfn(1)=xfn(1)/2; %Normalize DC
mag_xfn=20*log10(abs(xfn));
figure(1);
plot(f,mag_xfn,'k');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
grid;

Do not use time data and input signal lines if you read the data from a file.

11/22/2004 . 28
Practical Usage of Fast Fourier Transform (FFT)

Reference

[1] M. L. Schiff, “Spectral Analysis Using Digital FFT Techniques,” System View Times, vol. 2,
April 1997.

[2] O. M. Solomon, “Windows Modify The Amplitude of Frequency Domain Functions,”


Instrumentation and Measurement Technology Conference, IMTC 92, pp. 339 - 344, May 1992.

[3] D. F. Elliott, K. R. Rao, Fast Transforms Algorithms, Analyses, Applications, Academic


Press, 1982.

[4] L. B. Jackson, Signals, Systems, and Transforms, Addison-Wesley Publishing Company,


1991.

[5] B. Liu, Digital Filters and The Fast Fourier Transform, Halsted Press, 1975.

[6] Affirma Spectre Circuit Simulator Reference, Cadence, June 2000.

[7] J. G. Proakis, D. G. Manolakis, Digital Signal Processing, Prentice Hall, 1996.

11/22/2004 . 29
Practical Usage of Fast Fourier Transform (FFT)

Appendix

Delta Sigma Modulator


Delta Sigma modulator is one of the well known and widely used circuit. Usually the modulator
operates at very high clock rate comparing the signal bandwidth. This property requires high
sampling rates and low frequency resolution at the same time. Therefore the FFT number can be
increased dramatically. For example the delta sigma modulator shown in Fig. A.1 requires
1.6384MHz sampling frequency. The frequency resolution is chosen 100Hz and the input signal
is at 1KHz. The output spectrum is shown in Fig. A.2. Although the input frequency is chosen
integer multiple of the frequency resolution the spectrum is not as expected. Since the
rectangular window’s sidelobe height is not low enough, near the input signal the spectrum
shows a straight line. To solve this problem, a window with low Sidelobe height should be used.
For example, Kaiser window with β = 20 cane be used. The Sidelobe will be more than 200 dB
below. The spectrum with Kaiser window is shown in Fig. A.3. Now it is possible to distinguish
the signals close to the input signal. However, since 3 dB bandwidth of Kaiser window is higher
than rectangular window, the signal occupies higher bandwidth. To reduce the signal bandwidth
the frequency resolution should be reduced further. If the frequency resolution is reduced 10Hz
the spectrum is shown in Fig. B.1. To reduce the Sidelobe further, β is chosen 30. The third
harmonic of the modulator is now more distinguishable. However, the simulation time is
increased 10 times comparing the 100Hz case.

FigureA.1 Delta Sigma Modulator

11/22/2004 . 30
Practical Usage of Fast Fourier Transform (FFT)

FigureA.2 Output Spectrum with Rectangular Window

Figure A.3 Output Spectrum with Kaiser Window

11/22/2004 . 31
Practical Usage of Fast Fourier Transform (FFT)

Figure A.4 Output Spectrum with Kaiser Window

Bulk-Driven Mixer
The conductivity of a Mosfet transistor is normally controlled by the gate-capacitance. The
voltage across the gate and source controls the conductivity of the channel. However, the drain
current can be controlled by the bulk voltage of the transistor. Under normal operating conditions
this is a parasitic effect and can degrade the performance by introducing unwanted gmb.
However, for some applications this parasitic effect can be used to construct simple mixer. The
gate and bulk are driven with signal and oscillator respectively. The square wave characteristic
of the Mosfet, generates mixing products of these two signals. The example circuit (Fig. B.1) is
designed in TSMC 0.35µm technology. The frequency resolution is selected 100 Hz in order to
distinguish the harmonics easily. The output is filtered using a first order filter to avoid the
aliasing. The cutoff frequency is selected 100 KHz . Since the sampling frequency is
1.6384MHZ, more than 20dB attenuation beyond the sampling frequency is guaranteed. The
spectrum is shown in Figs. B.2 and B.3. Since the circuit is single unbalanced mixer, the input
signals appear at the output. The mixing products and harmonics can be easily separated. There
are also the mixing products of harmonics with input signals.

11/22/2004 . 32
Practical Usage of Fast Fourier Transform (FFT)

Vdd=3.3V

1m

out
10µ/0.35µ
Vo=0V
Vo=1.3V
Va=10mV
Va=1mV
freq=9K
freq=2K

Figure B.1: Bulk-Driven Mixer Schematic

Figure B.2 Output Spectrum of Bulk-Driven Mixer

11/22/2004 . 33
Practical Usage of Fast Fourier Transform (FFT)

Figure B.3: Output Spectrum of Bulk-Driven Mixer (1KHz - 100KHz)

11/22/2004 . 34

You might also like