Laas  6.003 Lab 2  April 9, 1999

6.003 Lab 2

Chris Laas Recitation 1, WF10

Friday, April 9, 1999

(a)

n = [0:1:999];
d0 = sin(0.7217*n)+sin(1.0247*n);
d1 = sin(0.5346*n)+sin(0.9273*n);
d2 = sin(0.5346*n)+sin(1.0247*n);
d3 = sin(0.5346*n)+sin(1.1328*n);
d4 = sin(0.5906*n)+sin(0.9273*n);
d5 = sin(0.5906*n)+sin(1.0247*n);
d6 = sin(0.5906*n)+sin(1.1328*n);
d7 = sin(0.6535*n)+sin(0.9273*n);
d8 = sin(0.6535*n)+sin(1.0247*n);
d9 = sin(0.6535*n)+sin(1.1328*n);

(b)

D2 = fft(d2,2048);
D9 = fft(d9,2048);
omega = linspace(0,2*pi*(1-1/2048),2048);
plot(omega,abs(D2));
axis([0.5 1.25 0 500]);
xlabel('\omega');
title('|D_2(e^{j\omega})|');
text(0.5346+0.01,450,'\omega=0.5346');
text(1.0247+0.01,450,'\omega=1.0247');
print D2.eps -deps

plot(omega,abs(D9));
axis([0.5 1.25 0 500]);
xlabel('\omega');
title('|D_9(e^{j\omega})|');
text(0.6535+0.01,450,'\omega=0.6535');
text(1.1328+0.01,450,'\omega=1.1328');
print D9.eps -deps

(c)

space = zeros(1,100);
phone = [d2 space d2 space d5 space d6 space d5 space d2 space d2];

(f)

kas = find(abs(fft(sin(0.5346*n),2048))>400);
ka = kas(1);
kbs = find(abs(fft(sin(0.5906*n),2048))>400);
kb = kbs(1);
kcs = find(abs(fft(sin(0.6535*n),2048))>400);
kc = kcs(1);
kds = find(abs(fft(sin(0.7217*n),2048))>400);
kd = kds(1);
kes = find(abs(fft(sin(0.9273*n),2048))>400);
ke = kes(1);
kfs = find(abs(fft(sin(1.0247*n),2048))>400);

kf = kfs(1);
kgs = find(abs(fft(sin(1.1328*n),2048))>400);
kg = kgs(1);
k = [ka kb kc kd ke kf kg];
omegak = 2*pi*k/2048;
% Results are:
% k =
%    175   193   214   236   303   335   370
% omegak =
%    0.5369    0.5921    0.6565    0.7240    0.9296    1.0278    1.1351

(g)

D8 = fft(d8,2048);
energyD8 = abs(D8).^2;
energies = energyD8(k);
% Results are:
% energies =
%    1.0e+05 *
%     0.0000    0.0020    2.5049    0.0005    0.0005    2.5022    0.0001
%
% Interpretation:
%  d8 has high energy at frequencies roughly 0.6565 and 1.0278.
%  This is as expected.

(ttdecode.m)

function digits = ttdecode(x)
rowks = [175 193 214 236];
colks = [303 335 370];
lookup = [ 1 2 3 ; 4 5 6 ; 7 8 9 ; -1 0 -1 ];
digits = [];
% Average is there to stop false transitions caused by sinewaves
% hitting zero.
silences = abs([0 x]+[x 0])<0.0001;
transitions = [0 silences] - [silences 0];
for start = find(transitions==1),
stops = find(transitions([start:length(transitions)])==-1);
if length(stops)>0

stop = stops(1)+start;
else
stop = length(x);
end;
dig=x([start:stop]);
DIG = fft(dig,2048);
energyDIG = abs(DIG).^2;
rowenergies = energyDIG(rowks);
colenergies = energyDIG(colks);
[val rows] = max(rowenergies);
row = rows(1);
[val cols] = max(colenergies);
col = cols(1);
num = lookup(row,col);
digits = [digits num];
end;

(h-i)

num1 = ttdecode(x1);
num2 = ttdecode(x2);
hardnum1 = ttdecode(hardx1);
hardnum2 = ttdecode(hardx2);
% Results are:
% num1 =
%      4     9     1     5     8     7     7
% num2 =
%      2     5     3     1     0     0     0
% hardnum1 =
%      4     9     1     5     8     7     7
% hardnum2 =
%      2     5     3     1     0     0     0