%% Fill Gaps in Audio File
% Load a speech signal sampled at F_s=7418\;\rm Hz. The file contains a recording of a female voice saying the word "MATLAB®." Play the sound.

load mtlb

% To hear, type soundsc(mtlb,Fs)

%
% Simulate a situation in which a noisy transmission channel corrupts parts of the signal irretrievably. Introduce gaps of random length roughly every 500 samples. Reset the random number generator for reproducible results.

rng default

gn = 3;

mt = mtlb;

gl = randi([300 600],gn,1);

for kj = 1:gn
    mt(kj*1000+randi(100)+(1:gl(kj))) = NaN;
end

%
% Plot the original and corrupted signals. Offset the corrupted signal for ease of display. Play the signal with the gaps.

plot([mtlb mt+4])
legend('Original','Corrupted')

% To hear, type soundsc(mt,Fs)

%
% Reconstruct the signal using an autoregressive process. Use fillgaps with the default settings. Plot the original and reconstructed signals, again using an offset. Play the reconstructed signal.

lb = fillgaps(mt);

plot([mtlb lb+4])
legend('Original','Reconstructed')

% To hear, type soundsc(lb,Fs)

% Copyright 2012 The MathWorks, Inc.