Sounds Logical
Send Page To a Friend

Table Of Contents Previous Page Next Page

[M-Pack 1 overview]

M-Pack 1: WAV file processing: MATLAB function reference

wavpeakfind
Version 1.2 Requires MATLAB 6.0 (R12) or later

Determines the peak absolute value of each channel of the input WAV file data. The file scan is performed chunk-by-chunk to avoid the need for large RAM allocations when scanning large files. Supports both WAVE_FORMAT_PCM and WAVE_FORMAT_EXTENSIBLE multichannel uncompressed formats and any bit resolution between 2 and 32 inclusive.

File format: m-file
Editable source code:
yes
Utilises non-editable functions: no
Platform:
PC/Windows
Required MATLAB Toolboxes: none (except core MATLAB)
Demo version limitations: p-code only (non-editable), 30 second WAV file length limit (then silence)
Syntax:
 

PeakAmplitude = wavpeakfind(InputWavFile);

  [PeakAmplitude, PeakLocation]= wavpeakfind(InputWavFile);
  [PeakAmplitude, PeakLocation]= wavpeakfind(InputWavFile,...
 
Tolerance);
  [PeakAmplitude, PeakLocation]= wavpeakfind(InputWavFile,...
 
Tolerance,Scaling);
  [PeakAmplitude, PeakLocation]= wavpeakfind(InputWavFile,...
 
Tolerance,Scaling,ReadChunkSize);
  [PeakAmplitude, PeakLocation]= wavpeakfind(InputWavFile,...
 
Tolerance,Scaling,ReadChunkSize,WaitbarActivate);
Arguments:
Inputs:
InputWavFile

name of the input WAV file.

Tolerance

Optional [default 0]: to be used in combination with the PeakLocation
output option (see below).

Scaling Optional argument [default 'full']. Describes the scaling law applied when reading the input WAV file. Identical to the scale argument in wavin. See wavin for full range of options.
ReadChunkSize

Optional argument [default value 65536]. Represents the length (in samples per channel) of each successive chunk to be processed. Can have an arbitrary value, but if too small, computational efficiency will be compromised since the file I/O operations are relatively slow. If too large, memory requirements may be excessive. (Note: the value is overridden if the file length happens to be smaller!)

WaitbarActivate

Optional argument. If the argument is present (even if empty), the progress is displayed via a waitbar which can be customized via the following optional fields:

  • Handle field (i.e. WaitbarActivate.Handle) the handle of an externally-generated waitbar figure. If omitted a new locally-generated waitbar is created (then deleted at the end of the function)
  • Label field (i.e. WaitbarActivate.Label) string containing the label of the waitbar

If this input argument is omitted, no waitbar will be used.

Note: any of the following input arguments: Tolerance, ReadChunkSize, WaitbarActivate, may be substituted by [ ] to force their respective default value(s).
Outputs:
PeakAmplitude

Vector containing peak absolute values, one element per channel.

PeakLocation

Optional argument: if specified, requires an additional scan (slower!)
Cell array containing the location indices of the peaks. One column of indices per channel.

Note: each channel can have more than one location for its peak since the peak may be repeated. The "Tolerance" input argument specifies "how close" a given value must be relative to the peak in order to be included. For example, a Tolerance of 0 suggests that only peaks of the same value (to floating point precision will be included). A Tolerance value of 0.1 suggests that all amplitudes that exceed 90% of the peak will be included, etc.

Inspect the source code of this function for a demonstration of how to use the wavin wavout function in chunk-by-chunk mode.

 

  wavnormalize WAV file normalization, uses wavpeakfind
Examples:
The following examples are contained in the m-script file entitled xmplwavpeakfind.m
 
Ex.1 Determine the peak amplitudes of each channel of the 4-channel WAV file '4channel.wav' (assuming default 'full' scale when reading -- which implicitly assumes that the data is contained within +/-1 when transformed from integer storage format)
 
  PeakAmplitude = wavpeakfind('4channel.wav')
  0.6793 0.6781 0.7940 0.9699
   
Ex.2 Same as above but with 'raw' scaling when reading (i.e. reads the integers directly without transforming to floating-point):
  PeakAmplitude = wavpeakfind('4channel.wav',[],'raw')
  22258 22219 26018 31783
 
Ex.3 Same as Ex.1 but with a waitbar (activated by including the 5th input argument, even if empty). Also, for example, override the default read chunk size with 1024 (thereby slowing down the process, albeit with less RAM usage):
 
  PeakAmplitude = wavpeakfind('4channel.wav',[],[],1024,[])
  0.6793 0.6781 0.7940 0.9699
 
Ex.4 Same as above but include the location output argument with zero tolerance (i.e. determine location of exact peaks only):
 
 

[PeakAmplitude, PeakLocation] =

 
wavpeakfind('4channel.wav',0,[],1024,[])
  PeakAmplitude =
  0.6793 0.6781 0.7940 0.9699
 
  PeakLocation =
  [7313] [97324] [47715] [135889]
   
  Plot the results:
  [y,fs]=wavin('4channel.wav'); plot(y); hold;
  for j=1:length(PeakLocation)
 
stem(PeakLocation{j},y(PeakLocation{j},j),'k.')
  end;
   
   
Ex.5 Same as above but include the location output argument with 5% tolerance (i.e. determine location of all points within 5% of the exact peaks).
 
   
 

[PeakAmplitude, PeakLocation] =

 
wavpeakfind('4channel.wav',0.05);
   
  Plot the results, noting the multiple sub-peaks within 5% of the exact peaks.
   

Top Of Page Table Of Contents Previous Page Next Page

Send Page To a Friend

home - news - products - store - support - site map - company info
© 2007 Sounds Logical. All rights reserved.
Sounds Logical
legal notice - privacy statement