classdef DigitalFilter < handle
%DigitalFilter Perform linear filtering operation
% Copyright 2008 The MathWorks, Inc.
% Author: Navan Ruthramoorthy
methods
function this = DigitalFilter()
[this.defaultB, this.defaultA] = butter(5, 0.5);
end
function y = filter(this, data, Fs) %#ok<INUSD,INUSL>
y = [];
FigureHandle = figure( ...
'Visible','off', ...
'Menubar','none', ...
'Toolbar','none', ...
'Position', [360,500,470,150], ...
'IntegerHandle', 'off', ...
'Color', get(0, 'defaultuicontrolbackgroundcolor'), ...
'NumberTitle', 'off', ...
'Name', 'Audio Editor: Filter');
movegui(FigureHandle, 'center');
uicontrol('Parent', FigureHandle, 'Style', 'Text', ...
'String', 'Numerator:', ...
'Units', 'Normalized', 'Position', [0 0.66 0.2 0.2], ...
'FontSize', 12);
hNum = uicontrol('Parent', FigureHandle, 'Style', 'edit', ...
'String', mat2str(this.defaultB, 2), ...
'Units', 'Normalized', 'Position', [0.2 0.66 0.78 0.2], ...
'FontSize', 12, 'BackgroundColor', 'white', ...
'HorizontalAlignment', 'left');
uicontrol('Parent', FigureHandle, 'Style', 'Text', ...
'String', 'Denominator:', ...
'Units', 'Normalized', 'Position', [0 0.33 0.2 0.2], ...
'FontSize', 12);
hDen = uicontrol('Parent', FigureHandle, 'Style', 'edit', ...
'String', mat2str(this.defaultA, 2), ...
'Units', 'Normalized', 'Position', [0.2 0.33 0.78 0.2], ...
'FontSize', 12, 'BackgroundColor', 'white', ...
'HorizontalAlignment', 'left');
uicontrol('Parent', FigureHandle, 'Style', 'pushbutton', ...
'String', 'Apply', 'Units', 'Normalized', ...
'Position', [0.1 0 0.4 0.2], 'FontSize', 12, ...
'Callback', @(hobj, evd) applyCallback());
uicontrol('Parent', FigureHandle, 'Style', 'pushbutton', ...
'String', 'Cancel', 'Units', 'Normalized', ...
'Position', [0.5 0 0.4 0.2], 'FontSize', 12, ...
'Callback', @(hobj, evd) cancelCallback());
set(FigureHandle,'Visible','on', 'CloseRequestFcn', ...
@(hobj, evd) cancelCallback);
uiwait(FigureHandle);
function applyCallback()
B = evalin('base', get(hNum, 'String'));
A = evalin('base', get(hDen, 'String'));
y = filter(B, A, data);
delete(FigureHandle);
end
function cancelCallback()
y = data;
delete(FigureHandle);
end
end
end
methods (Static)
function name = getName()
name = 'Digital Filter';
end
end
properties (Access=private)
defaultB;
defaultA;
end
end