tom@516: % Copyright 2012, Google, Inc. tom@516: % Author: Richard F. Lyon tom@516: % tom@516: % This Matlab file is part of an implementation of Lyon's cochlear model: tom@516: % "Cascade of Asymmetric Resonators with Fast-Acting Compression" tom@516: % to supplement Lyon's upcoming book "Human and Machine Hearing" tom@516: % tom@516: % Licensed under the Apache License, Version 2.0 (the "License"); tom@516: % you may not use this file except in compliance with the License. tom@516: % You may obtain a copy of the License at tom@516: % tom@516: % http://www.apache.org/licenses/LICENSE-2.0 tom@516: % tom@516: % Unless required by applicable law or agreed to in writing, software tom@516: % distributed under the License is distributed on an "AS IS" BASIS, tom@516: % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. tom@516: % See the License for the specific language governing permissions and tom@516: % limitations under the License. tom@516: tom@516: function MultiScaleSmooth(waves, n_scales) tom@516: % function MultiScaleSmooth(waves, n_scales) tom@516: % tom@516: % Let's take columns as waveforms, and smooth them to different scales; tom@516: % these inputs can be carfac NAPs, for example, and the peaks of the tom@516: % smoothed versions can be used as trigger events, even tracking back tom@516: % to less-smoothed versions. tom@516: % And we'll deciamte 2:1 at every other smoothing. tom@516: % tom@516: % Until we decide what we want, we'll just plot things, one plot per scale. tom@516: tom@516: fig_offset1 = 10; tom@516: fig_offset2 = 30; tom@516: fig_offset3 = 50; tom@516: tom@516: if nargin < 2 tom@516: n_scales = 20; tom@516: end tom@516: tom@516: smoothed = waves; tom@516: tom@516: for scale_no = 1:n_scales tom@516: tom@516: if mod(scale_no, 2) == 1 tom@516: newsmoothed = filter([1, 1]/2, 1, smoothed); tom@516: diffsmoothed = max(0, smoothed - newsmoothed); tom@516: smoothed = newsmoothed; tom@516: else tom@516: newsmoothed = filter([1, 2, 1]/4, 1, smoothed); tom@516: diffsmoothed = max(0, smoothed - newsmoothed); tom@516: smoothed = newsmoothed(1:2:end, :); tom@516: end tom@516: tom@516: figure(scale_no + fig_offset1) dicklyon@523: imagesc(squeeze(smoothed(:,:,1))') tom@516: tom@516: figure(scale_no + fig_offset2) dicklyon@523: plot(squeeze(mean(smoothed, 2))); tom@516: tom@516: drawnow tom@516: pause(1) tom@516: tom@516: end tom@516: tom@516: tom@516: function waves = deskew(waves) tom@516: tom@516: for col = 1:size(waves, 2) tom@516: waves(1:(end-col+1), col) = waves(col:end, col); tom@516: end tom@516: