Integration of New Filter .m Files

12 views
Skip to first unread message

MU Speech Lab

unread,
Jun 9, 2008, 4:51:16โ€ฏPM6/9/08
to xbat-devel
I am trying to integrate a new .m file into the Xbat code. I have
already created our own subgroup in the filter's category, and am just
trying to get our .m's to coincide with the program's read-in
function. If you can give me any insight into trying to get new
filters into the program, any help would be appreciated. I am doing
this for Marquette University's Speech Lab. I will post an example .m
Filter file here:

x being the input sound
Fs being the sampling rate
--------------------------------------


function [y] = spec_sub(x,Fs,t,nf)

l=t*Fs;
x=x(:);
n=length(x);
x(n+1:n+4*l)=zeros(4*l,1);
overlap=l/2;
num_frames=floor(n/(l-overlap)+1);

%Noise spectrum estimation from the silence frames of data.
%disp('Noise Estimation...');
%noise1=x(1:l);
%noise2=x(l+1:2*l);
%noise3=x(2*l+1:3*l);
%noise(1,:)=abs(fft(noise1'));
%noise(2,:)=abs(fft(noise2'));
%noise(3,:)=abs(fft(noise3'));
%ave_noise=mean(noise);
for i=1:nf%num_win_noise
An(:,i)=x(1+(i-1)*l/2:l + (i-1)*l/2);
end
N = abs(fft(An.*repmat(hanning(l),1,nf)));%num_win_noise)));
clear An
ave_noise=mean(N');


% Computation of FFT(magnitude and phase) for each window
%disp('FFT Computation...');
for i=1:num_frames
frame=x((i-1)*(l-overlap)+1:(i-1)*(l-overlap)+l);
frame=frame.*hanning(l); %Triangular windowing
frame_fft=fft(frame);
ang_frame(:,i)=angle(frame_fft);
mag_frame(:,i)=abs(frame_fft);
end

% Magnitude Averaging over 3 windows
%disp('Magnitude Averaging...');
for i=2:num_frames-1
mag_frame(:,i)=(mag_frame(:,i-1)+mag_frame(:,i)+mag_frame(:,i+1))/
3;
end

% Spectral Subtraction with Half-Wave rectification
%disp('Spectral Subtraction...');
for i=1:num_frames
enhanced_mag=mag_frame(:,i)-ave_noise';
for j=1:l
if enhanced_mag(j) < 0
enhanced_mag(j)=0;
end
end
% Phase information from noisy speech is added to enhanced speech
fft_y=enhanced_mag.*cos(ang_frame(:,i))
+j*enhanced_mag.*sin(ang_frame(:,i));
time_y(:,i)=real(ifft(fft_y));
end

% Reconstruction(Hanning)
%disp('Reconstruction...');
y(1:l-overlap)=time_y(1:l-overlap,1);
for i=1:num_frames-1
y(i*(l-overlap)+1:i*(l-overlap)+l-overlap)=time_y(l-overlap+1:l,i)
+time_y(1:l-overlap,i+1);
end
y=y(1:n);
%subplot(211),plot(x(1:n));
%title('Noisy Speech Signal');
%ylabel('Amplitude');
%xlabel('Samples');
%ax=axis;
y=real(max(x)/max(real(y))*y);
y=y';
%subplot(212),plot(y);
%plot(y);
%title('Enhanced Speech Signal');
%ylabel('Amplitude');
%xlabel('Samples');
%axis(ax);


----------------------------------------------------


Thank you in advance.

-Mike

Marquette University Undergraduate Research Assistant

Harold Figueroa

unread,
Jun 12, 2008, 5:05:22โ€ฏPM6/12/08
to xbat-...@googlegroups.com
Hello Mike,

OK, so I presume that you have created a 'signal filter' extension and
you want this extension to apply your code to the signal being
browsed.

Your extension should have a 'compute' function, have you done this?
Once you have this, which will be in FILTER_ROOT/private/compute.m
you will see that it has the following signature:

[X, context] = compute(X, parameter, context)

Your function has a signature:

> function [y] = spec_sub(x,Fs,t,nf)

Try calling your existing function from within the filter's compute
function ... you just have to figure out how to set 't' and 'nf', Fs
is available as get_sound_rate(context.sound) ... in current
development versions of XBAT it is simply context.sound.rate you can
test if it is available in the current preview release I can't
remember.

So if you were to edit the filter's compute function to be something like:

[X, context] = compute(X, parameter, context)

t = SOME_VALUE; nf = SOME_VALUE;

X = spec_sub(X, get_sound_rate(context.sound), t, nf)

It should just work ... so you see that the programming interface is
very minimal, and essentially the same as yours.

In XBAT the various parameters used by an algorithm are packed into a
'parameter' struct, this makes adding new ones and renaming them
trivial, and it also makes the related computation code clearer as
every time a parameter is used you will see parameter.(PARAMETER_NAME)
...

Harold

MU Speech Lab

unread,
Jul 1, 2008, 3:41:42โ€ฏPM7/1/08
to xbat-devel
So, I really appreciate the reply, but I'm having a few problems. I
feel that I had figured out the GUI pretty well, and putting in new
parameters. The issue I am encountering is that while I have
constructed the GUI as needed, it fails to update into the code. For
instance, I can put a slider with the value of my given parameter, but
the parameter doesn't update. It will stay with the 'default' value
given in parameter_create. Please let me know if I'm overlooking
something trivial.

-Mike






On Jun 12, 4:05 pm, "Harold Figueroa" <harold.figue...@gmail.com>
wrote:

Harold Figueroa

unread,
Jul 2, 2008, 6:25:00โ€ฏAM7/2/08
to xbat-...@googlegroups.com
Hello Mike,

Do you have a 'parameter__create' function? I presume so, but you did
not mention it. Creating an extension that has controllable parameter
consists of at least two possibly more (up to 4: create, compile,
control, callback) related functions.

First of all, to simply separate function declaration from the
computation code, you create a parameter__create function ... by
editing the parameter fields in this function your compute function
should get different parameter values, these are well
'editor-controlled parameters' ...

Now when you add a parameter__control__create function, this function
assists in the creation of controls to display the state of the
parameters. You do not set new parameter values in this function, just
display.

Let me know if this makes sense and I can help more , the other
'methods' to compile parameters and callback on the controls are
frequently not needed so I will not describe these yet.

Harold

MU Speech Lab

unread,
Jul 2, 2008, 3:04:03โ€ฏPM7/2/08
to xbat-devel
Harold-

I apologize if I was not very clear, I will try and be overly
descriptive this time. This might be a little long, as I will be
posting the individual files as well. Let me begin with again,
thanking you for taking the time to look at this.

Under the \XBAT_PRE_R5\Extensions\Filters\Signal I have created my own
individual folder named Spec_Sub.
This naming of the folder, my understanding, puts the name of the
filter into the GUI under the filters menu.

Within the Spec_Sub folder I have a list of 4 files/folders:
Presets ---- Which will remain empty, and probably could have been
deleted.
README --- Which I have edited for my own file descriptions.
Spec_Sub --- A file which is nothing more than the following:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ext = spec_sub

ext = extension_create;

ext.category = {'Marquette'};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Private (folder)- Which contains the following files.
compute
parameter_control_create
parameter_create
spec_sub


I will first start by copying my compute file:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [X, context] = compute(X, parameter, context)


X = spec_sub(X, get_sound_rate(context.sound), parameter.l,
parameter.nf);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I have set the compute file as you had said, passing the parameter
values into my function.
-- Although looking at this now, I am unsure if this is what you meant
by passing through the parameter."_" value.



My parameter_control_create file is as follows:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function control = parameter__control__create(parameter, context)

% CLIP - parameter__control__create

% Copyright (C) 2002-2007 Harold K. Figueroa (hk...@cornell.edu)
% Copyright (C) 2005-2007 Matthew E. Robbins (me...@cornell.edu)
%
% This file is part of XBAT.
%
% XBAT is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% XBAT is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with XBAT; if not, write to the Free Software
% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA

control = empty(control_create);

control(end + 1) = control_create( ...
'name', '# of Samples', ...
'style', 'slider', ...
'min', 128, ...
'max', 1024, ...
'slider_inc', [128, 128], ...
'value', parameter.l ...
);

control(end + 1) = control_create( ...
'name', '# of Frames', ...
'style', 'slider', ...
'type', 'integer', ...
'min', 1, ...
'max', 10, ...
'slider_inc', [1, 2], ...
'space', 1.5, ...
'value', parameter.nf ...
);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

This has given me the GUI which I desired, with the ranges and
increments I wished to have. Although, when the GUI values were
changed, the parameter."_" values were not passed through.



Lastly is my parameter_create file which is as follows:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function parameter = parameter__create(context)

% CLIP - parameter__create

% Copyright (C) 2002-2007 Harold K. Figueroa (hk...@cornell.edu)
% Copyright (C) 2005-2007 Matthew E. Robbins (me...@cornell.edu)
%
% This file is part of XBAT.
%
% XBAT is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% XBAT is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with XBAT; if not, write to the Free Software
% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA

parameter = struct;

parameter.l = 256;

parameter.nf = 3;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I have posted the spec_sub file earlier on, and don't wish to take up
room on this post.

I hope that this makes it a bit more clear about what I am working
with. I feel as if I'm close and missing something very rudimentary.
Please help in anyway that you can. If this issue can be resolved, I
feel that I can make the user interfaces very useful for my lab work.


Thank you in advance,

Michael Sagan
Marquette University Undergraduate Research



On Jul 2, 5:25 am, "Harold Figueroa" <harold.figue...@gmail.com>
wrote:
> Hello Mike,
>
> Do you have a 'parameter__create' function? I presume so, but you did
> not mention it. Creating an extension that has controllable parameter
> consists of at least two possibly more (up to 4: create, compile,
> control, callback) related functions.
>
> First of all, to simply separate function declaration from the
> computation code, you create a parameter__create function ... by
> editing the parameter fields in this function your compute function
> should get different parameter values, these are well
> 'editor-controlled parameters' ...
>
> Now when you add a parameter__control__create function, this function
> assists in the creation of controls to display the state of the
> parameters. You do not set new parameter values in this function, just
> display.
>
> Let me know if this makes sense and I can help more , the other
> 'methods' to compile parameters and callback on the controls are
> frequently not needed so I will not describe these yet.
>
> Harold
>

Harold Figueroa

unread,
Jul 2, 2008, 6:16:22โ€ฏPM7/2/08
to xbat-...@googlegroups.com
Hello again,

The 'name' of the controls should match the parameter fieldname, you
can use the 'alias' property to change the label of the control. I
think this should solve your problem ... if you look closely at the
code now you might recognize that otherwise there is no information
being passed to the control as to which parameter field it represents.

Now as a guideline, I would reccomend using a more descriptive name
for your parameter fields, which of course will be shared with the
matching control ... the name of this field will become the default
control label after title capitalization ... a good parameter name can
prevent you from using the alias ... and writing one less line of
code, it also typically makes the compute code more expressive to a
human.

Harold

MU Speech Lab

unread,
Jul 3, 2008, 12:55:03โ€ฏPM7/3/08
to xbat-devel
Harold,

Well, thank you, that did it. I feel a bit dense for overlooking that.

Again, thank you, and I hope that we here at Marquette can help
further along this program with the filters we plan on instituting.

-Mike




On Jul 2, 5:16 pm, "Harold Figueroa" <harold.figue...@gmail.com>
wrote:
> Hello again,
>
> The 'name' of the controls should match the parameter fieldname, you
> can use the 'alias' property to change the label of the control. I
> think this should solve your problem ... if you look closely at the
> code now you might recognize that otherwise there is no information
> being passed to the control as to which parameter field it represents.
>
> Now as a guideline, I would reccomend using a more descriptive name
> for your parameter fields, which of course will be shared with the
> matching control ... the name of this field will become the default
> control label after title capitalization ... a good parameter name can
> prevent you from using the alias ... and writing one less line of
> code, it also typically makes the compute code more expressive to a
> human.
>
> Harold
>
> > % Copyright (C) 2002-2007 Harold K. Figueroa (h...@cornell.edu)
> > % Copyright (C) 2002-2007 Harold K. Figueroa (h...@cornell.edu)
> ...
>
> read more ยป
Reply all
Reply to author
Forward
0 new messages