Sie sind auf Seite 1von 21

Scanned by CamScanner

Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
QUESTION – 3
Solution:
x=speech2_10k;
w=triang(300);
[s p t]=spectrogram(x,w,150);
z=ifft(s);
k=zeros(1,257*16);
for j=1:1:16
for i=1:257
k(1+(j-1)*257)=z(i,j);
end
end

[c,t]=istft(s,300,150,1024,10000)
figure(1);
subplot(2,1,1);
plot(x);
title('Speech Signal');
subplot(2,1,2);
plot(c)
title('Reconstructed Signal')
function [x, t] = istft(stft, wlen, hop, nfft, fs)

% function: [x, t] = istft(stft, wlen, hop, nfft, fs)


% stft - STFT matrix (only unique points, time across columns, freq across rows)
% wlen - length of the synthesis Hamming window
% hop - hop size
% nfft - number of FFT points
% fs - sampling frequency, Hz
% x - signal in the time domain
% t - time vector, s
% signal length estimation and preallocation
coln = size(stft, 2);
xlen = wlen + (coln-1)*hop;
x = zeros(1, xlen);

% form a periodic hamming window


win = triang(wlen, 'periodic');

% initialize the signal time segment index


indx = 0;

% perform ISTFT (via IFFT and Weighted-OLA)


if rem(nfft, 2) % odd nfft excludes Nyquist point
for col = 1:coln
% extract FFT points
X = stft(:, col);
X = [X; conj(X(end:-1:2))];

% IFFT
xprim = real(ifft(X));
xprim = xprim(1:wlen);

% weighted-OLA
x((indx+1):(indx+wlen)) = x((indx+1):(indx+wlen)) + (xprim.*win)';

% update the index


indx = indx + hop;
end
else % even nfft includes Nyquist point
for col = 1:coln
% extract FFT points
X = stft(:, col);
X = [X; conj(X(end-1:-1:2))];

% IFFT
xprim = real(ifft(X));
xprim = xprim(1:wlen);
% weighted-OLA
x((indx+1):(indx+wlen)) = x((indx+1):(indx+wlen)) + (xprim.*win)';

% update the index


indx = indx + hop;
end
end

% scale the signal


W0 = sum(win.^2);
x = x.*hop/W0;

% generate time vector


t = (0:xlen-1)/fs;

end

close all;
clear all;

window_size_1 = 300;
frame_rate_1 = 150;

%Speed to slow down by


speed = 2;

[sample_data] = importdata('ex7M1.mat');

loop_time = floor(max(size(sample_data))/frame_rate_1);

sample_data((max(size(sample_data))):(loop_time+1)* frame_rate_1)=0;
%%%%%%%%%%%%%%%%
% Create Windows
%%%%%%%%%%%%%%%%
% Want windows of 25ms
% File sampled at 10,000 samples/sec
% Want a window of size 10000 * 20ms(10ms)
triangle_30ms = triang(window_size_1);
%triangle_30ms = hamming(window_size_1);

%%%%%%%%%%%%%%%%
% Window the speech
%%%%%%%%%%%%%%%%

for i =0:loop_time-1

window_data(:,i+1)=sample_data((frame_rate_1*i)+1:((i+2)*
frame_rate_1))*triangle_30ms(:);

end

W0 = sum(triangle_30ms);
%%%%%%%%%%%%%%%%
% Create FFT
%%%%%%%%%%%%%%%%

for i = 1:loop_time

window_data_fft(:,i) = fft(window_data(:,i),1024);

end
%%%%%%%%%%%%%%%%
% Recreate Original Signal
%%%%%%%%%%%%%%%%

%Initialize the recreated signals

reconstructed_signal(1:(loop_time+1)*frame_rate_1)=0;
real_reconstructed_signal(1:(loop_time+1)*frame_rate_1)=0;
modified_reconstructed_signal(1:(loop_time+3)*(frame_rate_1/speed))=0;
modified_reconstructed_signal_compressed(1:(loop_time+3)* (frame_rate_1/ speed))=0;
% Perform the ifft

for i = 1:loop_time
recreated_data_ifft(:,i) = ifft(window_data_fft(:,i),1024);
real_recreated_data_ifft(:,i) = ifft(abs(window_data_fft(:,i)),1024);

truncated_recreated_data_ifft(:,i) =
recreated_data_ifft(1:window_size_1,i).*(frame_rate_1/W0);

real_truncated_recreated_data_ifft(:,i) =
real_recreated_data_ifft(1:window_size_1,i).*(frame_rate_1/W0);

end
% Get back to the original signal

for i=0:loop_time-1

reconstructed_signal((frame_rate_1*i)+1:((i+2)*frame_rate_1)) =
reconstructed_signal((frame_rate_1*i)+1:((i+2)*frame_rate_1)) +
truncated_recreated_data_ifft(:,i+1)';

real_reconstructed_signal((frame_rate_1*i)+1:((i+2)*frame_rate_1)) =
real_reconstructed_signal((frame_rate_1*i)+1:((i+2)*frame_rate_1)) +
real_truncated_recreated_data_ifft(:,i+1)';

end
% Get a modified signal by deleting certain parts (STFT)

for i=0:(loop_time-1)/speed

modified_reconstructed_signal((frame_rate_1*i)+1:((i+2)* frame_rate_1)) =
modified_reconstructed_signal((frame_rate_1*i)+1:((i+2)*frame_rate_1)) +
real_truncated_recreated_data_ifft(:,i*speed+1)';

end
% Initialize the compressed sequence (STFTM)

modified_reconstructed_signal_compressed(1:frame_rate_1+frame_rate_1/speed+1)=truncated_
recreated_data_ifft(frame_rate_1-frame_rate_1/speed:window_size_1,1)';

% Get a modified signal by compressing

for i=0:(loop_time-2)

modified_reconstructed_signal_compressed((frame_rate_1/speed*i)+1:(frame_rate_1/speed*i)+
window_size_1) =
modified_reconstructed_signal_compressed((frame_rate_1/speed*i)+1:(frame_rate_1/speed*i)+
window_size_1) + real_truncated_recreated_data_ifft(:,i+2)';

end
%%%%%%%%%%%%%%%%
% Plot Results
%%%%%%%%%%%%%%%%

figure; subplot(2,1,1);
plot(sample_data)
title('Original Speech'); v1=axis;
hold on; subplot(2,1,2);
plot(real(modified_reconstructed_signal))
title(['STFT Synthesis w/ Speed = ',num2str(speed),'X']); v2=axis;
if speed > 1
subplot(2,1,1); axis(v1)
subplot(2,1,2); axis(v1)
else
subplot(2,1,1); axis(v2)
subplot(2,1,2); axis(v2)
end
%%%%%%%%%%%%%%%%
% Write sound files
%%%%%%%%%%%%%%%%
QUESTION-4

SOLUTION:

figure(1);
subplot(4,1,1);
plot(filter1);
subplot(4,1,2);
plot(filter2);
subplot(4,1,3);
plot(filter3);
subplot(4,1,4);
plot(filter4);
(c)
y=uniform_bank(250,filter1,100);
impulse=impulse';

for i=1:1:21
z(:,i)= conv(impulse,y(:,i));
end
figure(1);
subplot(2,1,1);
plot(z(:,2));
title('Impulse response to the 2nd band pass filter');
subplot(2,1,2);
plot(z(:,15));
title('Impulse response to the 15th band pass filter');
(d)
y=uniform_bank(250,filter2,100);
impulse=impulse';

for i=1:1:21
z(:,i)= conv(impulse,y(:,i));
end
figure(1);
subplot(2,1,1);
plot(z(:,2));
title('Impulse response to the 2nd band pass filter');
subplot(2,1,2);
plot(z(:,15));
title('Impulse response to the 15th band pass filter');
(e)
y=uniform_bank(250,filter3,2);
impulse=impulse';

for i=1:1:21
z(:,i)= conv(impulse,y(:,i));
end

figure(1);
subplot(2,1,1);
plot(z(1:1:450,2));
title('Impulse response to the 2nd band pass filter');
subplot(2,1,2);
plot(z(1:1:450,15));
title('Impulse response to the 15th band pass filter');
(f)
y=uniform_bank(250,filter4,2);
impulse=impulse';

for i=1:1:21
z(:,i)= conv(impulse,y(:,i));
end

figure(1);
subplot(2,1,1);
plot(z(1:1:450,2));
title('Impulse response to the 2nd band pass filter');
subplot(2,1,2);
plot(z(1:1:450,15));
title('Impulse response to the 15th band pass filter');

Das könnte Ihnen auch gefallen