% Setiv1.m % % % Initialization clear all; pack; clc; pause(0.5); % Setable Parameters viewgraphs = 0; % if 1 then show plot, fft, specgram % warning, takes forever fileext = '.wav'; workingRAM = 400; % in Mb, RAM available after loading matlab workingdir = 'E:\MATLABR11\work\'; % READING, NORMALIZING AND WRITING OUT THE DATA % User picks wav file from directory's list % cd(workingdir) % for testing pick a specific file filename = 'min15'; % 96 sec at work, 150 sec at home %filename = 'hour'; % 368 sec at work ext = '.wav'; filen = strcat(workingdir, filename, ext); %d = dir('*.au') %str = {d.name}; %[s,v] = listdlg('PromptString','Select data file:',... % 'SelectionMode','single',... % 'ListString',str) %npts = auread(char(str(s)), 'size') % # of points in au file % load wavefile into workspace disp('Reading in wav file'); [y,fs,format] = wavread16(filen); T = 1/fs; % T is the period npts = size(y); % Normalize the data % set range to -1 to 1 and remove mean % if format(6) = 8 % 8 bits, -128 to +128 y = (y - mean(y))/128; % assume for now 8 bit mono % end % write file out since it is too big to keep in memory disp('Writing out normalized raw file'); rawfile = strcat(workingdir, filename, '.raw'); fid = fopen(rawfile, 'w'); if fid==-1 error('Failure to open raw file for writing'); end count = fwrite(fid, y, 'double'); fclose(fid); if count ~= npts(1) error('Failure to write out complete raw file'); end % clear large data matrix and repack memory clear y pack % PROCESSING 2^n SIZED BLOCKS OF DATA % Givens % 1. Window size runs from 2^14 for 2 sec % to 2^19 for 64 secs % How much to read at a time to process % n 2^n # of 2^n windows possible % with padding on last window % ------------------------------------------------------ %a = [[14:19; 2.^(14:19)]' ceil((npts(1)./2.^(14:19))')] %a = 14 16384 1758 % 15 32768 879 % 16 65536 440 % 17 131072 220 % 18 262144 110 % 19 524288 55 fid = fopen(rawfile, 'r'); if fid==-1 error('Failure to open raw file for reading'); end disp('Begining Processing'); tic for powerof2 = 14:19 % should be 14:19 disp(['Window Size = 2^', num2str(powerof2)]); % total # vectors possible with 2^powerof2 for file size totalnumwindows = ceil((npts(1)/2^(powerof2))); if totalnumwindows < 2 break end disp([num2str(totalnumwindows),... ' total number of windows this size']); % nww = # of vectors of size 2^powerof2 to read in at a time. nww = floor((workingRAM-50)*1000000/(8*10*2^powerof2)); disp(['Processing ', num2str(nww), ' windows as a matrix']); % set file position pointer at begining of file pause(0.5); % for disp to appear frewind(fid); for k =1:nww:totalnumwindows % BEGINING MAIN PROCESSING AREA FOR VECTORIZED OPERATIONS Y = fread(fid, [2^powerof2 nww], 'double'); %pause(0.2); % for control-C halting for program fftY = abs(fft(Y, 2^powerof2)); % END OF MAIN PROCESSING AREA FOR VECTORIZED OPERATIONS size(fftY) if viewgraphs % takes forever for kk = 1:nww subplot(3,1,1); plot(Y(:,kk)) subplot(3,1,2); bar(fftY(1:(2^powerof2/2+1),kk)) subplot(3,1,3); specgram(Y(:,kk)) drawnow; pause(1); % graphs won't update without delay end % kk for loop end % visual if end % k for loop end % powerof2 loop t = toc; disp(['elapsed time: ',num2str(round(t)), ' sec']) fclose(fid); disp('Finished Setiv1.m')