Home > chronux > test > testspecgram.m

testspecgram

PURPOSE ^

cd 'C:\Documents and Settings\Admin\Desktop\';

SYNOPSIS ^

function testspecgram(data)

DESCRIPTION ^

cd 'C:\Documents and Settings\Admin\Desktop\';
data=wavread('bird109_26519_on_Aug_19_16_33.wav');

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function testspecgram(data)
0002 
0003 
0004 %cd 'C:\Documents and Settings\Admin\Desktop\';
0005 %data=wavread('bird109_26519_on_Aug_19_16_33.wav');
0006 
0007 params.tapers = [3 5];
0008 params.fpass = [100 20000];
0009 params.Fs = 44100;
0010 params.pad = 2;
0011 max_time =10; % seconds per run
0012 max_tapers = 150;
0013 increment = 1.5;
0014 profile on
0015 
0016 
0017 nsamples = 1000;
0018 if 1
0019 slow_results = [];
0020     
0021 while 1
0022     tic
0023     [S,t,f] = mtspecgramc_slow( data(1:nsamples), [0.01 0.001], params );
0024     time = toc;
0025     result = [nsamples time];
0026     fprintf( 'ran %d samples in %d seconds\n',nsamples, time );
0027     slow_results = [slow_results ;result];
0028     if time > max_time 
0029         break
0030     end
0031     nsamples = round(nsamples * increment);
0032 end
0033 slow_results
0034 fig=figure();
0035 ax=axes('XScale','log','YScale','log');
0036 axes(ax);
0037 h=line( 'Xdata',slow_results(:,1),'Ydata',slow_results(:,2),'Marker','*');
0038 xlabel('number of samples')
0039 ylabel('time');
0040 title('Original mtspecgramc');
0041 grid on
0042 drawnow;
0043 saveas(fig,'datalength_slow.png');
0044 
0045 nsamples = 1000;
0046 fast_results = [];
0047 while 1
0048     tic
0049     [S,t,f] = mtspecgramc( data(1:nsamples), [0.01 0.001], params );
0050     time = toc;
0051     result = [nsamples time];
0052     fprintf( 'ran %d samples in %d seconds\n',nsamples, time );
0053     fast_results = [fast_results ;result];
0054     if time > max_time 
0055         break
0056     end
0057     nsamples = round(nsamples * increment);
0058 end
0059 fast_results
0060 fig=figure();
0061 ax=axes('XScale','log','YScale','log');
0062 axes(ax);
0063 h=line( 'Xdata',fast_results(:,1),'Ydata',fast_results(:,2),'Marker','*');
0064 xlabel('number of samples')
0065 ylabel('time');
0066 title('Modified mtspecgramc - preallocate space');
0067 grid on
0068 drawnow;
0069 saveas(fig,'datalength_fast.png');
0070 
0071 compare = [];
0072 n = 1;
0073 while n <= min(length(slow_results(:,1)),length(fast_results(:,1)))
0074     compare_one = [slow_results(n,1) slow_results(n,2)/fast_results(n,2)];
0075     compare = [compare ;compare_one];
0076     n = n + 1; 
0077 end
0078 compare
0079 fig=figure();
0080 ax=axes('XScale','log','YScale','lin');
0081 axes(ax);
0082 h=line( 'Xdata',compare(:,1),'Ydata',compare(:,2),'Marker','*');
0083 title('Preallocation slowdown/speedup of mtspecgramc');
0084 xlabel('number of samples')
0085 ylabel('speedup');
0086 grid on
0087 drawnow;
0088 saveas(fig,'speedup.png');
0089 
0090 
0091 end;
0092 
0093 nsamples=10000;
0094 results = [];
0095 n = 1;
0096 while 1
0097     tic
0098     params.tapers = [n (2*n-1)];
0099     [S,t,f] = mtspecgramc( data(1:nsamples), [0.01 0.001], params );
0100     time = toc;
0101     result = [params.tapers(2) time];
0102     fprintf( 'ran %d samples in %d seconds with tapers %d %d\n',nsamples, time,params.tapers(1),params.tapers(2) );
0103    results = [results ;result];
0104     if time > max_time || params.tapers(2) > max_tapers
0105         break
0106     end
0107     n = round(n * increment);
0108 end
0109 fig=figure();
0110 ax=axes('XScale','log','YScale','log');
0111 axes(ax);
0112 h=line( 'Xdata',results(:,1),'Ydata',results(:,2),'Marker','*');
0113 xlabel('tapers')
0114 ylabel('time');
0115 
0116 drawnow;
0117 saveas(fig,'tapers.png');
0118 
0119 
0120 stats = profile('info')

Generated on Fri 28-Sep-2012 12:34:30 by m2html © 2005