You are on page 1of 3

Digital Signal Processing

Activity #5
Fourier Series and Fourier Transform

A. A program that plot the Fourier series of a given function:

t=0:0.1:4*pi;
y1=sin(t)*(4/pi);
y3=sin(t)*(4/pi)+sin(3*t)*(4/(3*pi));
y5=sin(t)*(4/pi)+sin(3*t)*(4/(3*pi))+sin(5*t)*(4/(5*pi));
plot(t,y1,t,y3,t,y5), hold on;
x=square (t);
plot(x,t), hold off;
plot(t,x),hold off;
plot(t,y1,t,y3,t,y5,t,x)
title('Fourier Series representation')
xlabel('F(t)')
legend('n=1','n=2', 'n=3','f(t)')

1. Code the scripts and record the result.


2. In not less than 50 words, comment on your result and discuss the Fourier series.

B. Application of Fourier Series Exercise(Touch-tone dialing)

We all use Fourier analysis without even knowing it: cell phones, DVDs, images, all involve Fourier transforms in
one form or another. This lab includes one exercise that illustrates the computation and interpretation of Fourier
analysis for a time signal (Touch-tone dialing).

The basis for touch-tone dialing on a phone is the Dual Tone Multi Frequency (DTMF) system. Basically, the
telephone-dialing pad acts as a 4x3 matrix (see figure 1 below).

A frequency is associated with each row and each column. These base frequencies are:
frow =[ 697 770 852 941];
fcol = [1209 1336 1477];

The tone generated by the button at position (i,j) is obtained by superposing the two fundamental tones with
frequencies frow(i) and fcol(j). Let us look for example at the signal corresponding to the button “5”. The Matlab
code for generating this signal will look like:

frow =[ 697 770 852 941];


fcol = [1209 1336 1477];
% First, we need to set than sampling rate:
Fs = 8192;
% Second, we set a vector of points in the time interval [0 0.25s] at this sampling rate:
t = 0:1/Fs:0.25;
% The tone generated by the button 5 is the sum of the fundamental signals with frequencies frow(2) and fcol(2):
y1 = sin(2*pi*frow(2)*t);
y2 = sin(2*pi*fcol(2)*t);
y = (y1+y2)/2;
% If you want to play that tone, use the command:
sound(y,Fs)

1. Code the script and hear the output


2. In not less than 50 words, discuss how the program works.
3. Try another button from 1 to # and in not less than 50 words, describe the different tone you hear.

C. Application of Fourier Series Exercise(Decoding a phone number)

An important question related to telephony: is it possible to determine a phone number by simply listening to
its signal? Let us consider again the signal corresponding to the button 5. Figure 2A shows the signal generated by the
program given above, in the time interval [0 0.015s]. Note that in this representation, it is difficult to identify the two
fundamental tones that make up this signal. It is possible however to identify these tones by performing a Fourier series
analysis of the signal: figure 2B shows the Fourier coefficients corresponding to this signal in the frequency range
corresponding to the DTMF frequencies. Cleary, this signal contains two fundamental tones, at frequencies 770 and
1336, and therefore corresponds to the button 5.

Code for generating this figure:


% Subplot 1: time signal
figure;
subplot(2,1,1);
plot(t,y,'-r')
% limit to first 0.015 s
axis([0 0.015 -1 1]);
xlabel('t(s)');
title('Tone for 5 button');
% Subplot 2: Fourier series
subplot(2,1,2)
% Compute Fourier series
p = abs(fft(y));
n = length(y);
% Get corresponding frequency values
f = (0:n-1)*(Fs/n);
plot(f,p);
axis([500 1700 0 300]);
% Find peak position
[peak_amp pealoc]=findpeaks(p,'Minpeakheight',200);
% peak_loc is in point; convert to frequency
freq=f(pealoc);
% Only keep values in DTMF range
peak_freq=freq(freq < 1700);
peak_height = peak_amp(freq < 1700);
hold on
str=num2str(int32(peak_freq));
text(peak_freq(1),peak_height(1),str(1));
text(peak_freq(2),peak_height(2),str(2));

1. Code the scripts and record the result.


2. In not less than 50 words, comment on the output

D. The FFT Matlab function


Generally when you work with digital audio, you don't have to implement your own FFT. Efficient
implementations already exist in many programming language libraries. For example, MATLAB has FFT and
inverse FFT functions, fft and ifft, respectively. We can use these to experiment and generate graphs of sound data
in the frequency domain. First, let's use sine functions to generate arrays of numbers that simulate single-pitch
sounds. We'll make three one-second long sounds using the standard sampling rate for CD quality audio, 44,100
samples per second. First, we generate an array of sr*s numbers across which we can evaluate sine functions,
putting this array in the variable t.

sr = 44100; %sr is sampling rate


s = 1; %s is number of seconds
t = linspace(0, s, sr*s);
x = cos(2*pi*110*t);
y = cos(2*pi*220*t + pi/3);
z = cos(2*pi*440*t + pi/6);
figure;
plot(t,x), hold off;
axis([0 0.05 -1.5 1.5]);
title('x');
figure;
plot(t,y);hold off;
axis([0 0.05 -1.5 1.5]);
title('y');
figure;
plot(t,z);hold off;
axis([0 0.05 -1.5 1.5]);
title('z');
a = (x + y + z)/3;
figure;
plot(t, a);hold off;
axis([0 0.05 -1.5 1.5]);
title('a = x + y + z');

1. Code the scripts and record the result.


2. In not less than 50 words, discuss how the program works.

Note: The figure is a graph of the sound wave in the time domain. You could call it an impulse response graph, although
when you’re looking at a sound file like this, you usually just think of it as “sound data in the time domain.” The term
“impulse response” is used more commonly for time domain filters. You might want to play the sound to be sure you have
what you think you have. The sound function requires that you tell it the number of samples it should play per second,
which for our simulation is 44,100.

sound(a, sr);
When you play the sound file and listen carefully, you can hear that it has three tones.

Using Fourier Transform Matlab library:

fftdata = fft(a);
fftmag = abs(fftdata);
figure;
freqs = [0: (sr/2)-1];
plot(freqs, fftmag(1:sr/2));
axis([0 600 0 8000]);

1. Include the Fourier Transform Matlab fft function to your previous code and record the result.
2. Write your observation to the last figure.

You might also like