%% Enhance Speech with a Lowpass Filter
% Lowpass filters allow you to remove high-frequency noise to improve the intelligibility of speech.
% Load a sound file with a person saying MATLAB®. The signal is sampled at 7418 Hz.

load mtlb

% To hear, type soundsc(mtlb,Fs)

%
% Add noise containing one-fourth of the power contained in the speech.

Npower = 1/4*rms(mtlb)^2;
Noise = sqrt(Npower)*randn(size(mtlb));

Nmtlb = mtlb + Noise;

% To hear, type soundsc(Nmtlb,Fs)

%
% A filter with the following specifications can remove high-frequency noise for a speech signal sampled at 7418 Hz without appreciably affecting intelligibility.
% Passband frequency: 1483.6 Hz
% Passband ripple: 0.02 dB
% Stopband frequency: 1669.05 Hz
% Stopband attenuation: 50 dB
% Use designfilt to design the filter. View its frequency response with freqz.

Fps = 1483.6;
Fst = 1669.05;

d = designfilt('lowpassfir', ...
               'PassbandFrequency',Fps,'PassbandRipple',0.02, ...
               'StopbandFrequency',Fst,'StopbandAttenuation',50, ...
               'SampleRate',Fs);
freqz(d)

%
% Filter the signal using filtfilt to avoid startup transients.

FNmtlb = filtfilt(d,Nmtlb);

% To hear, type soundsc(FNmtlb,Fs)

% The filter attenuates the high-frequency noise. It also attenuates the high-frequency voice components.
% Copyright 2015 The MathWorks, Inc.