close all;
clear all;

[xn1 fs] = wavread('micChest.wav');    
[yn1 fs] = wavread('piezoChest.wav');
[xn2 fs] = wavread('micSpeech.wav');    
[yn2 fs] = wavread('piezoSpeech.wav');
[xn3 fs] = wavread('micEnglish.wav');    
[yn3 fs] = wavread('piezoEnglish.wav');
[xn4 fs] = wavread('micKorean.wav');    
[yn4 fs] = wavread('piezoKorean.wav');
[xn5 fs] = wavread('micRip.wav');    
[yn5 fs] = wavread('piezoRip.wav');

% fft
N = 8192;
w = hann(N);

fni = [0:fs/N:fs-fs/N];
Xn1 = abs(fft(xn1,N));
Yn1 = abs(fft(yn1,N));
Xn1_N = Xn1/max(Xn1);
Yn1_N = Yn1/max(Yn1);
Hn1 = Yn1_N./Xn1_N;
Xn2 = abs(fft(xn2,N));
Yn2 = abs(fft(yn2,N));
Xn2_N = Xn2/max(Xn2);
Yn2_N = Yn2/max(Yn2);
Hn2 = Yn2_N./Xn2_N;
Xn3 = abs(fft(xn3,N));
Yn3 = abs(fft(yn3,N));
Xn3_N = Xn3/max(Xn3);
Yn3_N = Yn3/max(Yn3);
Hn3 = Yn3_N./Xn3_N;
Xn4 = abs(fft(xn4,N));
Yn4 = abs(fft(yn4,N));
Xn4_N = Xn4/max(Xn4);
Yn4_N = Yn4/max(Yn4);
Hn4 = Yn4_N./Xn4_N;
Xn5 = abs(fft(xn5,N));
Yn5 = abs(fft(yn5,N));
Xn5_N = Xn5/max(Xn5);
Yn5_N = Yn5/max(Yn5);
Hn5 = Yn5_N./Xn5_N;

fni = 0:fs/N:fs-fs/N;
xbound = 2000;
ybound = 40;
figure(1)
subplot(511)
plot(fni,Xn1_N); xlim([0 xbound]);
title('air conducted sound by microphone(N=8192), Chest');
ylabel('Magnitude');
subplot(512)
plot(fni,Xn2_N); xlim([0 xbound]);
title('Speech Ah');
ylabel('Magnitude');
subplot(513)
plot(fni,Xn3_N); xlim([0 xbound]);
title('English');
ylabel('Magnitude');
subplot(514)
plot(fni,Xn4_N); xlim([0 xbound]);
title('Korean');
ylabel('Magnitude');
subplot(515)
plot(fni,Xn5_N); xlim([0 xbound]);
title('Rip');
xlabel('Frequency (Hz)');
ylabel('Magnitude');

figure(2)
subplot(511)
plot(fni,Yn1_N); xlim([0 xbound]);
title('bone(skull) conducted sound by piezo, Chest');
ylabel('Magnitude');
subplot(512)
plot(fni,Yn2_N); xlim([0 xbound]);
title('Speech Ah');
ylabel('Magnitude');
subplot(513)
plot(fni,Yn3_N); xlim([0 xbound]);
title('English');
ylabel('Magnitude');
subplot(514)
plot(fni,Yn4_N); xlim([0 xbound]);
title('Korean');
ylabel('Magnitude');
subplot(515)
plot(fni,Yn5_N); xlim([0 xbound]);
title('Rip');
xlabel('Frequency (Hz)');
ylabel('Magnitude');

figure(3)
subplot(511)
plot(fni,Hn1); xlim([0 xbound]);  ylim([0 ybound]);
title('transfer funtion from microphone pickup to piezo pickup, Chest, ZOOM IN');
ylabel('Magnitude');
subplot(512)
plot(fni,Hn2); xlim([0 xbound]);  ylim([0 ybound]);
title('Speech Ah');
ylabel('Magnitude');
subplot(513)
plot(fni,Hn3); xlim([0 xbound]);  ylim([0 ybound]);
title('English');
ylabel('Magnitude');
subplot(514)
plot(fni,Hn4); xlim([0 xbound]); ylim([0 ybound]);
title('Korean');
ylabel('Magnitude');
subplot(515)
plot(fni,Hn5); xlim([0 xbound]); ylim([0 ybound]);
title('Rip');
xlabel('Frequency (Hz)');
ylabel('Magnitude');