%Janod Al-Janoud, Evan Sthapit, Saba Kiani
%Matrikelnummern 913336,884334,....

%Aufgabe 1

fa = 16000;
Ta= 1/fa;

f1= 500;
f2=1000;
f3= 2000;

N= 16;
t=[0:Ta:5-Ta];
A_1= 1;
A_2= 0.5;
A_3 = 0.25;
phi1 = 0;
phi2 = -pi/2;
phi3 = pi;

A_t1 = A_1 * sin( 2 * pi * f1 * t +phi1);
A_t2 = A_2 * sin( 2 * pi * f2 * t +phi2);
A_t3 = A_3 * sin( 2 * pi * f3 * t +phi3);

plot (t,A_t1,t,A_t2,t,A_t3);
axis ([0 0.02 -1 +1]); 
ylabel ('A_t1'), xlabel ('s');

audiowrite('A1.wav',A_t1,fa);
audiowrite('A2.wav',A_t2,fa);
audiowrite('A3.wav',A_t3,fa);

N = 100; 
%N = 320000 %für 0,05s; 
%N = 160000 %für 0,01s; 
%N = 32000 %für 0,5s; 
%N = 16000 %für 1s,
%N = 3200 %für 5s;
F_f1 = fft(A_t1, N);
F_f2 = fft(A_t2,N);
F_f3 = fft(A_t3,N);

plot(fa, abs(F_f1),fa, abs(F_f2), fa, abs(F_f3));
xlabel('Frequenz(Hz)'), ylabel('Amplitude');

delta_f = fa/N;

fr = [0:delta_f:fa-delta_f];
plot(fr, abs(F_f1),fr, abs(F_f2),fr, abs(F_f3)), xlabel('Frequenz(Hz)'), ylabel('Ampltude(f)');

y = audioread('Janod_A.wav');
sound(y)
plot(abs(fft(y,50)))
axis ([0 50 0 40]);
ylabel ('Amplitude'), xlabel ('Frequenz(Hz)');
