comparison util/classes/tests/test_buffer.m @ 182:f8bc99a5470c danieleb

Added test for audio buffer function
author Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk>
date Mon, 09 Jan 2012 12:58:00 +0000
parents
children
comparison
equal deleted inserted replaced
181:0dc98f1c60bb 182:f8bc99a5470c
1 %% Buffer Test
2 % Test script for the function audio->buffer which takes an audio object as
3 % an input and buffers it into frames. The test assesses wether all the
4 % possible buffer methods are invertible.
5 %%
6
7 N = 500; % number of audio samples
8 TOL = 200; % tolerance (in decibels)
9 verb = true; % verbose
10
11 obj = audio(randn(N,1)); % audio object
12 % wLengts: one window, two windows, maximum number of windows
13 temp = factor(N);
14 wLengths = [N; fix(N/2); fix(N/temp(end))];
15 % overlaps: zero, half window, max
16 overlapNames = {'zero','half-window','maximum'};
17 overlaps = {@(n)0, @(n)n/2, @(n)n-1};
18 % windows: valid windows
19 windows = {@hanning,@hamming,@triang,@rectwin};
20 % methods: valid methods
21 methods = {'standard'};
22
23
24 nLen = length(wLengths);
25 nOver = length(overlaps);
26 nWin = length(windows);
27 nMet = length(methods);
28 count = 1;
29 for iLen=1:nLen
30 for iOver=1:nOver
31 for iWin=1:nWin
32 for iMet=1:nMet
33 if verb
34 printf('\n buffer test %d/%d - %d window length, %s overlap, %s window and %s method ... ',...
35 count,nMet*nWin*nOver*nLen,wLengths(iLen),overlapNames{iOver},func2str(windows{iWin}),methods{iMet});
36 end
37 obj = buffer(obj,wLengths(iLen),overlaps{iOver}(wLengths(iLen)),windows{iWin},methods{iMet});
38 s_rec = obj.unbuffer;
39 if snr(obj.s,s_rec) > TOL
40 if verb, printf('Passed'); end
41 else
42 error('Test failed!');
43 end
44 count = count+1;
45 end
46 end
47 end
48 end