E71 Lab 6 (Brian Park, Mark Piper, David Luong, Aron Dobos) 23 March 2006

Contents

Part 1: Computing the DFT of two signals using one FFT call

% This lab is to demonstrate the use of the FFT to compute DFT and to
% demonstrate some of the tricks that one might do with FFT.
% The DFT of two sequences x0(n) and x1(n) can be computed with one
% FFT call on the sequence v(n) = x0(n) + j*x1(n).  We compute the
% DFT of the sequences x0(n) and x1(n) using the relationships
% X0(k) = (V(k)+V*(N-k))/2 and X1(k) = (V(k)-V*(N-k))/2j.  This is
% demonstrated below for N=256 and x0=sin(2*pi*n/6) and x1=cos(2*pi*n/8).

clc;clear all;close all;

n = 0:255;

% define the functions
x0 = sin(2*pi*n/6);
x1 = cos(2*pi*n/8);

% compute the DFTs of x0, x1
x0FFT = fft(x0);
x1FFT = fft(x1);

% compute v = x0 + j*x1
v = x0 + j*x1;
vFFT = fft(v);

% recombine to obtain the DFTs of x0, x1
x0FFT2 = (vFFT+conj(circshift(fliplr(vFFT),[0 1])))/2;
x1FFT2 = (vFFT-conj(circshift(fliplr(vFFT),[0 1])))/(2*j);

% plot to verify that the DFTs are the same
figure;plot(n,abs(x0FFT),'o',n,abs(x0FFT2));
title('sin(2*pi*n/6)');legend('direct FFT','indirect FFT');
figure;plot(n,abs(x1FFT),'o',n,abs(x1FFT2));
title('cos(2*pi*n/8)');legend('direct FFT','indirect FFT');

Part 2: Computing a 2N point real DFT as a N point complex DFT

% In this part, we compute a real DFT of length 2N as an N point
% complex DFT.  This is demonstrated below for a sequence with N=256.

clc;clear all;close all;
nx = 0:511;
% define x(k)
x = exp(-0.01.*nx).*sin(2*pi*0.2*nx);
ny = 0:255;
% define y(k) = x(2n) + j*x(2n+1)
y = x(2*ny+1) + j*x(2*ny+2);

% compute the fft of the complex sequence
yfft = fft(y);

% obtain the two FFTs as in part 1
y1fft = (yfft + conj(circshift(fliplr(yfft),[0 1])))/2;
y2fft = (yfft - conj(circshift(fliplr(yfft),[0 1])))/(2*j);

% recombine x(2n) and x(2n+1) to obtain g and gN
for i=1:256,
    g(i)=y1fft(i) + exp(-j*pi*i/256)*y2fft(i);
end
for i=1:256,
    gN(i)=y1fft(i) - exp(-j*pi*i/256)*y2fft(i);
end

xfft = fft(x);

% plot to verify
figure;plot(nx,abs(xfft),'o',nx,abs(cat(2,g,gN)),'x');
title('exp(-0.01*n)*sin(2*pi*0.2*n)');legend('direct FFT','indirect FFT');