Skip to content

Commit

Permalink
All the files and source codes for the Case Study 1
Browse files Browse the repository at this point in the history
  • Loading branch information
aieask authored Mar 11, 2022
1 parent 7c40f9b commit c8b6cfe
Show file tree
Hide file tree
Showing 52 changed files with 645 additions and 0 deletions.
Binary file added casestudy1/19BEC001MLSCVA01.pdf
Binary file not shown.
Binary file added casestudy1/mlscv_casestudy1.pdf
Binary file not shown.
26 changes: 26 additions & 0 deletions casestudy1/question1/STEn_STM_calc.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function [STEn, STMag] = STEn_STM_calc(speech, WL_samp, WS_Samp, fs)



Num_frames = round( (length(speech)-WL_samp)/WS_Samp );
STEn = zeros(1,Num_frames);
STMag = zeros(1,Num_frames);

for i=1:Num_frames
startsamp = (i-1)*WS_Samp+1;
EndSamp = startsamp+WL_samp-1;
CurrSpeech = speech(startsamp :EndSamp);
CurrSpeechWin = (CurrSpeech).*hamming(WL_samp);
STEn(i) = sum(CurrSpeechWin.*CurrSpeechWin);
STMag(i) = sum(abs(CurrSpeechWin));


% if(i==11)
%
% FFTSpec = fft(CurrSpeechWin, 512);
% freq = (0:256)*(fs/512);
% figure; plot (freq, 20*log10( abs(FFTSpec(1:257))),'LineWidth',2);
% temp=1;
% end
end

Binary file added casestudy1/question1/abhishek_record.wav
Binary file not shown.
68 changes: 68 additions & 0 deletions casestudy1/question1/calc_MFCC.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
function [MFCC, logFiltBankOut, logFiltBankFreq] = calc_MFCC(speech, N_filters, N_FFT, fs)
% calculate the MFCC now.
fmax = fs/2;
Mel_fmax = 1127*log(1+ (fmax/700));

% obtain the center frequencies in mel scale
N = N_filters;
% N_FFT = 512;
m=0:(N+1);
c = m*(Mel_fmax/(N+1));

% convert these to linear frequencies
h = 700* (exp(c/1127) - 1);

% convert to DFT indices
g = round( (N_FFT*h)/fs) + 1; % +1 added due to MatLab indexing 1

% Obtain the filterbank coefficients
temp=1;

H = zeros(N, (N_FFT/2)+1);
for m=2:N+1
for k=1:(N_FFT/2)+1
if( k< g(m-1) || k>g(m+1))
H(m-1, k) = 0;
else
if(k>=g(m-1) && k<=g(m))
H(m-1, k) = (k-g(m-1))/(g(m)-g(m-1));
else
H(m-1, k) = (g(m+1)-k)/(g(m+1)-g(m));
end

end
end
end


%%%%%%%%%%%%calculating MFCC %%%%%%%%%%

spec = abs( fft(speech.*hamming(length(speech)), N_FFT));

% Filter the spectrum using
spec = spec( 1: (N_FFT/2)+1);

% size(spec)
% size(H)
Fout = H* spec;
logFiltBankOut = log(Fout);
logFiltBankFreq = g(2:N+1) * (fs/N_FFT);

% DCT calculation

for l=1:13
DCTout_temp=0;
for m=1:N
DCTout_temp = DCTout_temp+ log(Fout(m))*cos( (pi*l*(m-0.5)) /N);
end
MFCC(l) = DCTout_temp;
end


% figure;
% for m=1:N
%
% plot(H(m, :), 'LineWidth', 2);
% hold on
% end
% axis tight
Binary file added casestudy1/question1/question1.mlx
Binary file not shown.
Binary file added casestudy1/question1/question1_fig.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions casestudy1/question1/spec_calc.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function [b,f,t] = spec_calc(data,NFFT,fs,windowSig,o_lap)

L = length(windowSig);
M = L - o_lap;
datalen = length(data);

noOfFrames = round(datalen/M);
frameInd = 1;
for i=1:noOfFrames
w_start = (i-1)*M + 1;
w_end = w_start + L -1;

if(w_start < 1)
w_start = 1;
end;
if(w_end > length(data))
break;

end;



h = windowSig;
Signal = data(w_start:w_end);

sn = Signal.*h;
XkTmep = fft(sn,NFFT);
Xk(frameInd,:) = XkTmep(1:NFFT/2);


frameInd = frameInd + 1;
end
f = (1:1:NFFT/2)*(fs/NFFT);
t = 0:(M/fs):(datalen/fs);
b = Xk';
26 changes: 26 additions & 0 deletions casestudy1/question2/STEn_STM_calc.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function [STEn, STMag] = STEn_STM_calc(speech, WL_samp, WS_Samp, fs)



Num_frames = round( (length(speech)-WL_samp)/WS_Samp );
STEn = zeros(1,Num_frames);
STMag = zeros(1,Num_frames);

for i=1:Num_frames
startsamp = (i-1)*WS_Samp+1;
EndSamp = startsamp+WL_samp-1;
CurrSpeech = speech(startsamp :EndSamp);
CurrSpeechWin = (CurrSpeech).*hamming(WL_samp);
STEn(i) = sum(CurrSpeechWin.*CurrSpeechWin);
STMag(i) = sum(abs(CurrSpeechWin));


% if(i==11)
%
% FFTSpec = fft(CurrSpeechWin, 512);
% freq = (0:256)*(fs/512);
% figure; plot (freq, 20*log10( abs(FFTSpec(1:257))),'LineWidth',2);
% temp=1;
% end
end

Binary file added casestudy1/question2/abhishek_aiu.wav
Binary file not shown.
Binary file added casestudy1/question2/abhishek_second.wav
Binary file not shown.
68 changes: 68 additions & 0 deletions casestudy1/question2/calc_MFCC.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
function [MFCC, logFiltBankOut, logFiltBankFreq] = calc_MFCC(speech, N_filters, N_FFT, fs)
% calculate the MFCC now.
fmax = fs/2;
Mel_fmax = 1127*log(1+ (fmax/700));

% obtain the center frequencies in mel scale
N = N_filters;
% N_FFT = 512;
m=0:(N+1);
c = m*(Mel_fmax/(N+1));

% convert these to linear frequencies
h = 700* (exp(c/1127) - 1);

% convert to DFT indices
g = round( (N_FFT*h)/fs) + 1; % +1 added due to MatLab indexing 1

% Obtain the filterbank coefficients
temp=1;

H = zeros(N, (N_FFT/2)+1);
for m=2:N+1
for k=1:(N_FFT/2)+1
if( k< g(m-1) || k>g(m+1))
H(m-1, k) = 0;
else
if(k>=g(m-1) && k<=g(m))
H(m-1, k) = (k-g(m-1))/(g(m)-g(m-1));
else
H(m-1, k) = (g(m+1)-k)/(g(m+1)-g(m));
end

end
end
end


%%%%%%%%%%%%calculating MFCC %%%%%%%%%%

spec = abs( fft(speech.*hamming(length(speech)), N_FFT));

% Filter the spectrum using
spec = spec( 1: (N_FFT/2)+1);

% size(spec)
% size(H)
Fout = H* spec;
logFiltBankOut = log(Fout);
logFiltBankFreq = g(2:N+1) * (fs/N_FFT);

% DCT calculation

for l=1:13
DCTout_temp=0;
for m=1:N
DCTout_temp = DCTout_temp+ log(Fout(m))*cos( (pi*l*(m-0.5)) /N);
end
MFCC(l) = DCTout_temp;
end


% figure;
% for m=1:N
%
% plot(H(m, :), 'LineWidth', 2);
% hold on
% end
% axis tight
Binary file added casestudy1/question2/figure1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added casestudy1/question2/figure2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added casestudy1/question2/figure3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added casestudy1/question2/figure4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added casestudy1/question2/figure5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added casestudy1/question2/figure6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added casestudy1/question2/figure7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added casestudy1/question2/question2.mlx
Binary file not shown.
35 changes: 35 additions & 0 deletions casestudy1/question2/spec_calc.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function [b,f,t] = spec_calc(data,NFFT,fs,windowSig,o_lap)

L = length(windowSig);
M = L - o_lap;
datalen = length(data);

noOfFrames = round(datalen/M);
frameInd = 1;
for i=1:noOfFrames
w_start = (i-1)*M + 1;
w_end = w_start + L -1;

if(w_start < 1)
w_start = 1;
end;
if(w_end > length(data))
break;

end;



h = windowSig;
Signal = data(w_start:w_end);

sn = Signal.*h;
XkTmep = fft(sn,NFFT);
Xk(frameInd,:) = XkTmep(1:NFFT/2);


frameInd = frameInd + 1;
end
f = (1:1:NFFT/2)*(fs/NFFT);
t = 0:(M/fs):(datalen/fs);
b = Xk';
26 changes: 26 additions & 0 deletions casestudy1/question3/STEn_STM_calc.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function [STEn, STMag] = STEn_STM_calc(speech, WL_samp, WS_Samp, fs)



Num_frames = round( (length(speech)-WL_samp)/WS_Samp );
STEn = zeros(1,Num_frames);
STMag = zeros(1,Num_frames);

for i=1:Num_frames
startsamp = (i-1)*WS_Samp+1;
EndSamp = startsamp+WL_samp-1;
CurrSpeech = speech(startsamp :EndSamp);
CurrSpeechWin = (CurrSpeech).*hamming(WL_samp);
STEn(i) = sum(CurrSpeechWin.*CurrSpeechWin);
STMag(i) = sum(abs(CurrSpeechWin));


% if(i==11)
%
% FFTSpec = fft(CurrSpeechWin, 512);
% freq = (0:256)*(fs/512);
% figure; plot (freq, 20*log10( abs(FFTSpec(1:257))),'LineWidth',2);
% temp=1;
% end
end

Binary file added casestudy1/question3/abhishek_aiu.wav
Binary file not shown.
Binary file added casestudy1/question3/abhishek_second.wav
Binary file not shown.
68 changes: 68 additions & 0 deletions casestudy1/question3/calc_MFCC.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
function [MFCC, logFiltBankOut, logFiltBankFreq] = calc_MFCC(speech, N_filters, N_FFT, fs)
% calculate the MFCC now.
fmax = fs/2;
Mel_fmax = 1127*log(1+ (fmax/700));

% obtain the center frequencies in mel scale
N = N_filters;
% N_FFT = 512;
m=0:(N+1);
c = m*(Mel_fmax/(N+1));

% convert these to linear frequencies
h = 700* (exp(c/1127) - 1);

% convert to DFT indices
g = round( (N_FFT*h)/fs) + 1; % +1 added due to MatLab indexing 1

% Obtain the filterbank coefficients
temp=1;

H = zeros(N, (N_FFT/2)+1);
for m=2:N+1
for k=1:(N_FFT/2)+1
if( k< g(m-1) || k>g(m+1))
H(m-1, k) = 0;
else
if(k>=g(m-1) && k<=g(m))
H(m-1, k) = (k-g(m-1))/(g(m)-g(m-1));
else
H(m-1, k) = (g(m+1)-k)/(g(m+1)-g(m));
end

end
end
end


%%%%%%%%%%%%calculating MFCC %%%%%%%%%%

spec = abs( fft(speech.*hamming(length(speech)), N_FFT));

% Filter the spectrum using
spec = spec( 1: (N_FFT/2)+1);

% size(spec)
% size(H)
Fout = H* spec;
logFiltBankOut = log(Fout);
logFiltBankFreq = g(2:N+1) * (fs/N_FFT);

% DCT calculation

for l=1:13
DCTout_temp=0;
for m=1:N
DCTout_temp = DCTout_temp+ log(Fout(m))*cos( (pi*l*(m-0.5)) /N);
end
MFCC(l) = DCTout_temp;
end


% figure;
% for m=1:N
%
% plot(H(m, :), 'LineWidth', 2);
% hold on
% end
% axis tight
Binary file added casestudy1/question3/fig1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added casestudy1/question3/fig10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added casestudy1/question3/fig2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added casestudy1/question3/fig3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added casestudy1/question3/fig4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added casestudy1/question3/fig5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added casestudy1/question3/fig6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added casestudy1/question3/fig7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added casestudy1/question3/fig8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added casestudy1/question3/fig9.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added casestudy1/question3/question3.mlx
Binary file not shown.
35 changes: 35 additions & 0 deletions casestudy1/question3/spec_calc.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function [b,f,t] = spec_calc(data,NFFT,fs,windowSig,o_lap)

L = length(windowSig);
M = L - o_lap;
datalen = length(data);

noOfFrames = round(datalen/M);
frameInd = 1;
for i=1:noOfFrames
w_start = (i-1)*M + 1;
w_end = w_start + L -1;

if(w_start < 1)
w_start = 1;
end;
if(w_end > length(data))
break;

end;



h = windowSig;
Signal = data(w_start:w_end);

sn = Signal.*h;
XkTmep = fft(sn,NFFT);
Xk(frameInd,:) = XkTmep(1:NFFT/2);


frameInd = frameInd + 1;
end
f = (1:1:NFFT/2)*(fs/NFFT);
t = 0:(M/fs):(datalen/fs);
b = Xk';
Loading

0 comments on commit c8b6cfe

Please sign in to comment.