%% Savitzky-Golay Filtering of Speech Signal
% Load a speech signal sampled at F_s =7418\;\textrm{Hz}. The file contains a recording of a female voice saying the word "MATLAB®."

load mtlb
t = (0:length(mtlb)-1)/Fs;

% Smooth the signal by applying a Savitzky-Golay filter of polynomial order 9 to data frames of length 21. Plot the original and filtered signals. Zoom in on a 0.02-second interval.

rd = 9;
fl = 21;

smtlb = sgolayfilt(mtlb,rd,fl);

subplot(2,1,1)
plot(t,mtlb)
axis([0.2 0.22 -3 2])
title('Original')
grid

subplot(2,1,2)
plot(t,smtlb)
axis([0.2 0.22 -3 2])
title('Filtered')
grid

%
% Repeat the calculation, but now use a Kaiser window as a weighting vector. Specify a shape factor \beta =38. Plot the new filtered signal.

kmtlb = sgolayfilt(mtlb,rd,fl,kaiser(fl,38));

subplot(2,1,2)
hold on
plot(t,kmtlb)
axis([0.2 0.22 -3 2])
hold off

%
% Copyright 2015 The MathWorks, Inc.