Sunteți pe pagina 1din 12

Lab 3: Frequency-domain analysis using the DFT

DSP Praktikum Signal Processing Group Technische Universitt Darmstadt a 10 May 2011

Introduction

During the process of learning signals and systems theory, you may have come across a point, where you got confused about all existing transforms, e.g. continuous-time Fourier transforms, Laplace, DFT and so on. As an overview, there exist four types among the Fourier transforms, as is shown in Table 1. Table 1: Fourier transforms. Discrete-time Discrete frequency Continuous frequency DFT DTFT Continuous-time Fourier series Standard FT

This practical will briey recap the discrete-time types in Table 1, namely the Discrete-time Fourier transform (DTFT) and the Discrete Fourier transform (DFT). You will learn that the DTFT is simply the Fourier transform of sampled signals, and discover some important properties. Furthermore, you will nd out more about the DFT and its relation to the DTFT of sampled and truncated signals. A comprehensive review on the evolution of discretetime Fourier transforms from continuous-time counterparts, well suited for an undergraduate learning perspective, can be downloaded from our webpage: 1

2 DISCRETE-TIME FOURIER TRANSFORM

J.R. Deller, Jr. Tom, Dick, and Mary Discover the DFT, IEEE signal processing magazine, April 1994. Within this practical we will consider discrete-time signals, which have been bandlimited and adequately sampled above the Nyquist rate corresponding to twice the highest frequency. MATLAB is used to compute the DTFT and investigate properties. We will illustrate the inuence of the window function, used for truncation and the concept of frequency resolution. Two hands-on applications are presented: The rst one shows how to use the DFT to decode touch-tone telephone dialing signals (DTMF). In the second one, we will articially reverberate a speech signal, and reconstruct it using the FFT-based fast convolution.

Discrete-time Fourier transform

This section reviews basic properties of the discrete-time Fourier transform (DTFT), whose analysis and synthesis are dened as

X ej =
n=

x(n)ejn

(1)

and x(n) =

1 2

X ej ejn d.

(2)

Here, we use x(n) to denote an innitely long signal, i.e. x(n) = 0 for n Z. Later on, we will use x(n) to denote a time-limited or truncated signal, satisfying x(n) = 0 only for n = 0, . . . , N 1. Some properties of the DTFT are: It is dened for innitely long signals. The DTFT is generally complex-valued, also for real x(n). It is a function of the continuous variable R. Note that is a normalized frequency variable and therefore dimensionless, in radians/sample. It is related to real frequency f in Hz by = 2f /fs . Due to the discrete-time nature of x(n), X(ej ) is periodic with period 2. Hence, it is sucient to look at one period only, [0, 2) or [, ).

2 DISCRETE-TIME FOURIER TRANSFORM

In the context of MATLAB, where computability is an issue, there are neither innitely long signals nor continuous variables. So we can only approximate the true DTFT, as dened in (1). The rst adjustment is interpreting a truncated signal as an innitely long signal which has been windowed. We will investigate the eect of windowing in the next section and the experiments. The other computability issue can be resolved by calculating the DTFT on a nite grid of frequencies k = 2k/M for k = 0, . . . , M 1. By choosing enough frequency points M, we can get a smooth approximation of the true DTFT.

2.1

Windowing

We are given a truncated signal x(n) = 0 for n = 0, . . . , N 1, which can be interpreted as a windowed version of the an innitely long signal x(n) x(n) = x(n)w(n) (3)

The window function satises w(n) = 0 for n = 0, . . . , N 1 only. There are many dierent window functions such as Bartlett, Hamming or Blackman, the simplest being the rectangular window, given by w(n) = 1 0n<N 0 otherwise

From theory, we know that multiplication in the time domain results in convolution in the frequency domain. Consequently, the DTFT of a truncated signal x(n) is the convolution in frequency between the DTFT of the window and the DTFT of the innitely long signal x(n) X e
j

1 = 2

X ej() W ej d

(4)

2.2

MATLAB example

We consider a sinusoidal signal x(n) = 0.8 sin(0.2n), which has been truncated by a rectangular window of length N = 32. In MATLAB, we can generate and plot x(n) by typing >> n=0:N-1; >> x=0.8*sin(0.2*pi*n); >> stem(n,x)

3 DISCRETE FOURIER TRANSFORM

1 0.5 x(n) 0 0.5 1

10

15 n

20

25

30

15

|X(e )|

10

Figure 1: Truncated sinusoidal signal and its DTFT. The DTFT is now approximated using an FFT with M = 16N frequency points (we will describe the concept of zero-padding the DFT/FFT in the next section). This can be done in MATLAB using >> >> >> >> M=16*N; w=2*pi*(0:1/M:1-1/M); X=fft(x,M); plot(omega,abs(X))

Note that the output of the fft function corresponds to a frequency interval [0, 2). Alternatively, the function fftshift can be used to transform the output of fft corresponding to a frequency interval [, ). The plot of x(n) and its DTFT is shown in Figure 1.

Discrete Fourier transform

It can be shown that the full information content of the DTFT of a truncated signal can be retained by only considering a nite number of samples, the so called DFT coecients. The remaining values of the DTFT can be interpolated.

3 DISCRETE FOURIER TRANSFORM

By evaluating the DTFT X (ej ) of a truncated signal x(n) on a nite grid of frequencies k = 2k/N for k = 0, . . . , N 1 we obtain the DFT coecients
N 1

X(k) = X ej

=k

=
n=0

x(n)ej N kn

(5)

The inverse transformation to (5) is given by 1 x(n) = N


N 1

X(k)ej N kn
k=0

(6)

3.1

MATLAB example

We use the same sinusoidal signal as in the previous MATLAB example. The DFT is computed using an FFT with M = N frequency points, where N is the signal length. This can be done in MATLAB using >> >> >> >> Xk=fft(x); N=length(Xk); wk=2*pi*(0:1/N:1-1/N); stem(wk,abs(Xk))

Figure 2 shows the DTFT from the last example, and the computed DFT coecients in the same plot. Note that for the case M = N, if the frequency of a sinusoid is a multiple of 2/N, the DFT magnitude is exactly N/2 for the peak sample and zero for the remaining samples.

3.2

DFT Computation

We continue by presenting a method to compute the DFT based on matrix notation. For this, we arrange x(n) and X(k) in column vectors x = [x(0), x(1), . . . , x(N 1)]T and X = [X(0), X(1), . . . , X(N 1)]T

3 DISCRETE FOURIER TRANSFORM

15 DTFT DFT

10 |X(e )| 5 0 0

Figure 2: DFT and DTFT of the truncated sinusoidal signal. which we do in MATLAB anyway. The DFT, as dened in (5), can now be conveniently expressed as a matrix vector product 2 2 2 ej N 01 ... ej N 0(N 1) ej N 00 2 2 ej 2 10 N ej N 11 ... ej N 1(N 1) X = (7) x. . . . .. . . . . . . . ej N (N 1)0 ej N (N 1)1 . . . ej N (N 1)(N 1)
2 2 2

Having calculated the DFT matrix once, it can be used for many DFT computations of the same length. Note that in MATLAB, a matrix multiplication is generally faster than two nested for loops. The computational complexity of (7) can be described in Big O notation by O(N 2 ). Another option to calculate the DFT, is to use the fast Fourier transform (FFT) algorithm. It is computationally more attractive and has a complexity of only O(N log(N)). The principle of the FFT algorithm is to recursively divide the computation of the DFT into smaller pieces and recombine the results. The respective MATLAB built-in function is fft.

3.3

Approximating the DTFT

In the rst MATLAB example we have seen that the DTFT can be approximated using a zeropadded DFT. We now describe the concept of

4 APPLICATION EXAMPLES

zeropadding in more detail. The basic idea is to evaluate the DFT of a signal with length N at a ner frequency grid, say at M > N frequency points which gives = 2k/M for k = 0, . . . , M 1. This can be written as
N 1 M 1

X(k) =
n=0

x(n)ej M kn =
n=0

x(n)ej M kn

(8)

where x(n) is the zeropadded version of the truncated signal x(n) satisfying x(n) = x(n) 0 n < N 0 N n<M (9)

In this case, signal x(n) has been padded with M N zeros.

3.4

Comments on the DFT/DTFT

Two comments on frequency resolution and the fast convolution are in order: The concept of resolution is often confused with granularity, which is just the accuracy of the frequency grid. Loosely speaking, resolution can be described as the ability to distinguish multiple peaks when two or more oscillations or sources are present. In the experiments we will discover the resolution limit of the DFT and how it is inuenced. Convolving long signals may be computationally demanding. Using multiple FFT operations poses a clear alternative, i.e. taking the FFTs of h(n) and x(n), multiplying the respective FFTs and taking the inverse FFT. For instance in MATLAB, you could use >> M=length(h)+length(x)-1; >> y=ifft(fft(h,M).*fft(x,M)); This is commonly referred to as fast convolution algorithm, and has complexity of O(N log(N)) when compared to the direct convolution with O(N 2 ).

Application examples

Two application examples are presented: DTMF signal decoding and inverse ltering for dereverberation of speech.

4 APPLICATION EXAMPLES

4.1

DTMF signal decoding

Dual-tone multi-frequency (DTMF) signals are commonly used for touchtone telephone dialing applications, i.e. transmission of the dialed number to the switching center. A DTMF signal consists of a sum of two tones x(n) = sin 2fr n + sin fs 2fc n fs 0nN 1

with frequencies taken from two mutually exclusive groups of preassigned frequencies, the so called row and column frequencies fr and fc . Their values and respective symbol meaning are given in Table 2. Table 2: Row and column frequencies of a DTMF signal. 1209 Hz 697 Hz 770 Hz 852 Hz 941 Hz 1 4 7 1336 Hz 2 5 8 0 1477 Hz 3 6 9
#

1633 Hz
A B C D

Each pair of tones represents a unique number or a symbol. Decoding of a DTMF signal thus involves computing the DFT, identifying the two tones in the signal and determining their corresponding number or symbol.

4.2

Inverse ltering for dereverberation of speech

Inverse ltering is a common problem in many engineering applications. The signal of interest is ltered by a system that somehow distorts the signal, e.g. transmission over a communication channel. We want to reverse this operation and thereby restore the signal of interest. A system is invertible if the input signal can be uniquely determined from the output signal. A system with impulse response h(n) is invertible if the inverse system with hi (n) is stable and satises

h(k)hi (n k) = (n)
k=

4 APPLICATION EXAMPLES In the frequency domain, this is equivalent to H(ej )Hi (ej ) = 1

In the considered scenario, a speaker is emitting an audio signal into a reverberating room. The signal observed by a listener exhibits some strong echos and reverberation, and will be hardly understandable. We assume perfect knowledge of the room parameters and use inverse ltering to restore the speech signal. To model a room impulse response (RIR), we consider a ray propagation model. The emitted sound waves propagate in many directions and are reected from walls or interior objects so that they arrive at the receiver from various directions, at various times. A simplied RIR is shown in Figure 3. It can be characterized by three main groups of impulses:
Direct sound Sound level Early reections

Reverberations

Time lag

Figure 3: A simplied room impulse response with various types of echoes. The direct sound represents waves coming directly to the listener. Closely spaced echoes, referred to as early reections, are reections of waves from all sides of the room and reaching the listener at irregular times. The reverberations are waves which have been reected several times, and are therefore decaying exponentially. The RIR generally depends on room size, wall reection coecients, room interiors and the transmitter and receiver locations. The easiest way to model the RIR is directly as an FIR lter. This may result in very long lters, e.g. a two second impulse response, sampled at 8 kHz results in an FIR lter with 16,000 tabs.

5 PREPARATION

10

Preparation
1. By hand, compute the DFT of x(n) = ej0.5n for n = 0, . . . , 3. What changes for Re{x(n)} = cos(0.5n)? 2. Derive the analytical expression for the DTFT of a rectangular window of length N. 3. The modulation propery is a special form of (4), where x(n) is a complex exponential. Using this and the result of preparation 2., derive the DTFT of x(n) = ej0 n for n = 0, . . . , N 1. 4. What are sidelobe level and mainlobe width of a window? 5. Briey state the problems of computing the DTFT, and how it can be approached.

6
6.1

Experiments
Computational complexity of the DFT/FFT
1. Write a MATLAB program dft for the direct computation of the DFT, using the described matrix notation. Check if your results are identical with those obtained via the fft function. 2. Use functions tic and toc to determine the approximate number of computations r(N) required by your routine dft and the fft function. Use signal length N = 2k for k = 4, . . . , 8. Plot the result against N and comment on the dependency.

6.2

Discrete-time Fourier transform

1. Write a MATLAB function dtft, which returns the DTFT of the input signal and a normalized frequency vector. For a smooth interpolation of the DTFT, use an FFT with sucient zeropadding. 2. Plot the DTFT of some common windows. To generate the windows, use MATLAB functions rectwin, bartlett and hamming. Vary the window length, e.g. N = 12 and 36. For all windows, measure sidelobe level and mainlobe width. What do you observe?

6 EXPERIMENTS

11

3. Plot the DTFT of a windowed sinusoid and relate this to the modulation property, as described in the preparation part. 4. Plot the DTFT of two sinusoids at dierent frequencies, using a rectangular and a Hamming window, for example x(n) = cos(0 n) + cos(1 n) n = 0, . . . , N 1 Use 0 = 0.2 and 1 = 0 + 2/N. Vary , which is a normalized frequency separation, to nd the resolution limit. Also vary the signal length N. What do you observe?

6.3

DTMF signal decoding

You are given the function dtmfdial, which takes as input a sequence of valid DTMF symbols and returns the corresponding DTMF signal. As sampling frequency we use 8 kHz, the duration of one signal is set to N = 256. 1. Generate the DTMF signal corresponding to the symbol 7. Plot its DTFT and highlight the relevant frequencies needed for a signal identication. 2. Write a function dtmfcoef, which evaluates the DTFT at the DTMF row and column frequencies. Now simply threshold your output of dtmfcoef, e.g. at N/4 and determine the dialed symbol. 3. Load the signal mynumber.mat into your workspace and decode it using your function dtmfcoef. You may have to split the signal sequence into single symbols rst.

6.4

Inverse ltering for dereverberation of speech

You are given the function rir.m. You may nd more informations about the used model, parameters etc. on http://2pi.us/rir.html. The help command shows you how to use rir along with a suggested parameter setting. Furthermore, a speech signal speech.wav is provided. 1. Generate a room impulse response and plot it. Import the speech signal into your workspace and listen to it. Use the functions wavread and soundsc.

6 EXPERIMENTS

12

2. Use the MATLAB function conv to convolve the impulse response and the speech signal, and listen to the ltered output. How long is the resulting vector? Play with the parameter settings, i.e. room size and reection coecient. Listen to the ltered outputs. 3. Use the fast convolution to restore the distorted speech signal. Think about the amount of zeropadding for the FFT and IFFT needed to receive an undistorted signal.

S-ar putea să vă placă și