%--------------------------------------------------
% Tony Hyun Kim
% 6.003: PS #5, Matlab assignment
%--------------------------------------------------

%--------------------------------------------------
% Problem (a)
%--------------------------------------------------
n = [0: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);

% Test (Wow, works very well)
% sound(d2,8192);

%--------------------------------------------------
% Problem (b)
%--------------------------------------------------
w  = (2*pi/2048) * [0:2047];
D2 = fft(d2, 2048);
D9 = fft(d9, 2048);
subplot(211);
plot(w,abs(D2).^2);
xlim([0.5, 1.25]);
xlabel('w');
ylabel('|D2|^2');
title('Power distribution in d2');
subplot(212);
plot(w,abs(D9).^2);
xlim([0.5, 1.25]);
xlabel('w');
ylabel('|D9|^2');
title('Power distribution in d9');

%--------------------------------------------------
% Problem (c)
%--------------------------------------------------
space = zeros(1,100);
phone = [d7 space d4 space d5 space d5 space d5 space d0 space d2];
sound(phone,8192);