You are on page 1of 6

SIGSLAB Page 4-1

De La Salle University
Electronics and Communications Engineering Department

Laboratory Experiment 4
Frequency Domain Representation and Analysis

I. Objectives:

[1] To display the frequency domain representation of a discrete-time signal and system using the
matlab function freqz.

[2] To observe the effects of aliasing in the frequency domain.

[3] To use the Matlab function fft/ifft in converting the time domain signal to its frequency domain
equivalent and vice versa.

[4] To plot the change in the frequency response of the signal as time increases using the matlab
function specgram.

[5] To use fft2 in getting the frequency domain representation of an image signal.

[6.] To display the magnitude spectrum of an image using the matlab function imagesc.

[7.] To display the magnitude spectrum of an image in 3D using the matlab function mesh and
meshgrid.

II. Introductory Information

Discrete-Time Fourier Transform

The frequency response of a discrete-time signal can be obtained by taking the discrete-time Fourier
transform defined by:

( )

=
n
jwn
e ] n [ x w X

Where x[n] is the discrete time signal, w is the angular frequency (0 to 2). It can be noticed that the
frequency response is periodic every 2. The angular frequency of the above equation is normalized,
meaning the 2 corresponds to the sampling frequency.

To display the frequency response of a discrete time signal with, the following matlab can be used:

freqz(x,1,512,Fs)

Where x is the discrete-time signal and Fs is the sampling rate. To ensure that the maximum gain is 0 dB
the frequency response plot can be normalized by dividing each sample by the summation of x. This is
accomplish using the following matlab code

freqz(x/sum(x),1,512,Fs)

Another way of displaying the frequency response of a discrete-time signal is by first computing the
discrete Fourier transform using the fast Fourier transform algorithm. In matlab, the fft can be computed as
follows:

SIGSLAB Page 4-2
X =fft(x)

Where X is the discrete time Fourier transform of x. It should be noted that the resulting number of samples
of X is the same as x and it is sampled from 0 to Fs with a resolution of Fs/length(x). To display the
frequency response in dB scale, the following matlab code can be used:

Step 1. Calculate the logarithmic scale of X.

Xlog =20*log10(abs(X)+1)

Step 2. Generate the frequency samples of X.

F =0:Fs/length(X):(length(x)-1)*Fs/length(X);

Step 3. Plot the frequency response.

Plot(F,Xlog)

To obtain the FFT of x with N number of samples, we use the following syntax:

X=fft(x,N)


Time-Frequency Response of a Discrete-time Signal

The freqz and fft of matlab compute the frequency component of a discrete-time signal. It does
not provide an information on the changes of its frequency response as time changes. The specgram
function of matlab can be used to display and computes the change of frequency as time increases.

specgram computes the windowed discrete-time Fourier transform of a signal using a sliding
window. The syntax is given by:

X =specgram(x,NFFT,Fs,WINDOW,NOVERLAP)

where nfft specifies the FFT length that specgram uses. This value determines the frequencies at which the
discrete-time Fourier transform is computed. Fs is a scalar that specifies the sampling frequency.
WINDOW specifies a windowing function and the number of samples specgram uses in its sectioning of
vector x. NOVERLAP is the number of samples by which the sections overlap.

Example:

[x,Fs,nbits]=wavread(c:\temp\tononoise8mono.wav);
t=0:1/Fs:(length(x)-1)/Fs;
subplot(211);plot(t,x);
subplot(212);specgram(x,512,Fs,hamming(256),128);

SIGSLAB Page 4-3

Figure 1. Spectogram plot of waveform tononoise8mono.

Frequency Response of a Discrete-Time System

A system can be represented by a difference equation given below:


= =
=
N
1 k
k
M
0 k
k
] k n [ y a ] k n [ x b ] n [ y

To display its frequency response, the following vectors must be defined:

] b b b [ b
M 1 0
m =

] a a a 1 [ a
N 2 1
m =

The frequency response of the system can be displayed using the matlab function:

freqz(b,a,512,Fs)

Frequency Response of a Two-Dimensional Signal

The two-dimensional Fourier Transform of a picture signal/ two-dimensional discrete-time system
can be obtained using the matlab fft2 function. The resulting frequency domain signal is complex;
however, for its graphical plot only the magnitude is of interest. A direct plot of its magnitude is not
desirable as its values widely differ, yielding an image that is mostly black. A logarithmic plot of its
SIGSLAB Page 4-4
magnitude spectra is more desirable, with the logarithm of the magnitude directly proportional to the
brightness of the pixels of the resulting image. Also, the resulting image can be interpreted as follows:



Figure 2. Frequency interpretation of a
two dimensional sequence

The figure above shows arrows that correspond to an increasing frequency. To ensure that the center is the
minimum frequency the spectrum image should be arrange as follows



Figure 3 Arranged Spectrum of a
Two dimensional sequence

The following MATLAB code displays the logarithmic magnitude spectra of lina_gray.tiff image file:

x=imread(lina_gray.tiff,tiff);
X=fft2(x,512,512);
Xabs=abs(X);
Xlog=log(1+Xabs);
subplot(221);colormap(gray(256)); image(a);axis off
subplot(222);colormap(gray(256)); imagesc(Xlog);axis off

This code displays the image and the magnitude spectra shown in Figure 4.


Figure 4. display of lena_gray,tiff and the corresponding spectrum

To display the spectrum shown in figure 3, the following code can be used:

subplot(223);colormap(gray(256));
SIGSLAB Page 4-5
imagesc([Xlog(257:512,257:512),Xlog(257:512,1:256);Xlog(1:256,257:512)
,Xlog(1:256,1:256)]); axis off


Figure 5. Magnitude spectrum of lena_gray.tiff

Consider a two dimension lowpass filter whose impulse response is given by:

=
1 1 1
1 1 1
1 1 1
h
9
1


The magnitude spectrum is computed as follows:

H=fft2(h,512,512);
Hlog=log(1+abs(H));
u=-256:255;
v=-256:255;
[u,v]=meshgrid(u,v);
subplot(221);imagesc([Hlog(257:512,257:512),Hlog(257:512,1:256);
Hlog(1:256,257:512),Hlog(1:256,1:256)]);axis off
subplot(222);mesh(u,v,[Hlog(257:512,257:512),Hlog(257:512,1:256);
Hlog(1:256,257:512) Hlog(1:256,1:256)]);


Figure 6. Magnitude spectrum of a low pass filter

III. Laboratory Exercise:

1. Plot the frequency response of the following signal using the matlab function freqz. Assume a
sampling frequency of 8000Hz and a resolution of 512 samples.


SIGSLAB Page 4-6
1.1 ( ) ( ) ( ) ( ) [ ] 31 n u n u cos x
4
n
n
3
2
=


1.2 ) 32 , 1 ( randn x =
1.3 ( ) [ ] 31 , 1 zeros 1 x =
1.4 See figure below


Figure 7. Square wave sequence, n =031


2. In speech processing, the frequency spectra changes in time and its spectogram can be displayed using
the following matlab code:

specgram(x,512,Fs,hanning(256),128)

where x is the speech samples. Plot the spectogram of tononoise8mono.wav and the filtered
tononoise8mono. Use the following filter coefficients:

b =[ 0.0947 0.2841 0.2841 0.0947]
a =[1.0000 -0.7130 0.6287 -0.1581]


3. Plot the frequency response of the following discrete-time system (Assume a sampling frequency of
8000 Hz and a frequency resolution of 512 samples)

3.1 [ ] [ ] [ ] [ ] n x 2 n y 36 . 0 1 n y 9 . 0 n y + + =
3.2 [ ] [ ] [ ] [ ] n x 2 n y 25 . 0 1 n y 8 . 0 n y + =
3.3 ( )
( )
( )
2 1
z 13 . 1 z 4 . 1 1
1
z X
z Y
z H

+
= =

4. Display the following: a.) the frequency spectrum of the image mapped_gray.jpg, b.) the image
mapped_gray.jpg, c.) the filtered image, d.) spectrum of the filtered image, e.) the spectrum of the two-
dimensional filter, and f.) the spectrum of the two-dimensional filter in 3D. The center of the spectrum
must be at the center and the resolution of the spectrum must be 512 x 512. Use the following filter
coefficients:




=
1 1 1
1 8 1
1 1 1
h

You might also like