tomwalters@0: % tomwalters@0: % Taper Window Generator for signal onset/offset tomwalters@0: % 7 Apr. 1993 tomwalters@0: % 29 Aug. 96 tomwalters@0: % IRINO Toshio tomwalters@0: % tomwalters@0: % function [TaperWin, TypeTaper] = ... tomwalters@0: % TaperWindow(LenWin,TypeTaper,LenTaper,RangeSigma,SwPlot) tomwalters@0: % INPUT LenWin : Length of Window (Number of points) tomwalters@0: % TypeTaper : Type of Taper (KeyWords of 3 letters) tomwalters@0: % (Hamming, Hanning (=cosine^2), Blackman, Gauss, Line) tomwalters@0: % LenTaper : Length of Taper (Number of points) tomwalters@0: % RangeSigma: Range in Sigma (default: 3) for Gauss tomwalters@0: % SwPlot : 0) Omit plotting, 1) Plot Taper tomwalters@0: % OUTPUT TaperWin : Taper Window Points (max==1); tomwalters@0: % TypeTaper : Type of Taper (Full Name) tomwalters@0: % tomwalters@0: function [TaperWin, TypeTaper] = ... tomwalters@0: TaperWindow(LenWin,TypeTaper,LenTaper,RangeSigma,SwPlot) tomwalters@0: tomwalters@0: if nargin < 2, tomwalters@0: help TaperWindow tomwalters@0: error([ 'Specify Type of Taper : ' ... tomwalters@0: ' Hamming, Hanning (=cosine^2), Blackman, Gauss, Line ']); tomwalters@0: %TaperWin = ones(1,LenWin); tomwalters@0: %return; tomwalters@0: end; tomwalters@0: tomwalters@0: if nargin < 3, LenTaper = fix(LenWin/2); end; tomwalters@0: if nargin < 4, RangeSigma = 3; end; tomwalters@0: tomwalters@0: if LenTaper*2 >= LenWin, tomwalters@0: disp('Caution (TaperWindow.m) : No flat part. '); tomwalters@0: if LenTaper ~= fix(LenWin/2), tomwalters@0: disp('Caution (TaperWindow.m) : LenTaper <-- fix(LenWin/2)'); tomwalters@0: end; tomwalters@0: LenTaper = fix(LenWin/2); tomwalters@0: end; tomwalters@0: tomwalters@0: if nargin < 5, SwPlot = 0; end; % changing default Swplot 29 Aug. 96 tomwalters@0: tomwalters@0: %TypeTaper = lower(TypeTaper(1:3)); tomwalters@0: tomwalters@0: if upper(TypeTaper(1:3)) == 'HAM', tomwalters@0: Taper = hamming(LenTaper*2)'; tomwalters@0: TypeTaper = 'Hamming'; tomwalters@0: elseif upper(TypeTaper(1:3)) == 'HAN' | upper(TypeTaper(1:3)) == 'COS', tomwalters@0: Taper = hanning(LenTaper*2)'; tomwalters@0: TypeTaper = 'Hanning/Cosine'; tomwalters@0: elseif upper(TypeTaper(1:3)) == 'BLA', tomwalters@0: Taper = blackman(LenTaper*2)'; tomwalters@0: TypeTaper = 'Blackman'; tomwalters@0: elseif upper(TypeTaper(1:3)) == 'GAU', tomwalters@0: if length(RangeSigma) == 0, RangeSigma = 3; end; tomwalters@0: nn = -LenTaper+0.5:1:LenTaper-0.5; tomwalters@0: Taper = exp(-(RangeSigma*nn/LenTaper).^2 /2); tomwalters@0: TypeTaper = 'Gauss'; tomwalters@0: else Taper = [1:LenTaper LenTaper:-1:1]/LenTaper; % 'line', tomwalters@0: TypeTaper = 'Line'; tomwalters@0: end; tomwalters@0: tomwalters@0: %plot(Taper) tomwalters@0: %size(Taper); tomwalters@0: LenTaper = fix(LenTaper); tomwalters@0: TaperWin = [ Taper(1:LenTaper) ones(1,LenWin-LenTaper*2) ... tomwalters@0: Taper(LenTaper+1:LenTaper*2)]; tomwalters@0: tomwalters@0: if SwPlot == 1, tomwalters@0: tomwalters@0: plot(TaperWin) tomwalters@0: xlabel('Points'); tomwalters@0: ylabel('Amplitude'); tomwalters@0: title(['TypeTaper = ' TypeTaper] ); tomwalters@0: tomwalters@0: end; tomwalters@0: