No BSD License  

Highlights from
exp.sweep and impulse response

from exp.sweep and impulse response by Matthes
generate exp. sine sweep and calculate impulse response and distortion

[sweep,invsweep]=expsweep(T,f1,f2,silence,fs)
function [sweep,invsweep]=expsweep(T,f1,f2,silence,fs)

% generate sine sweep with exponential frequency dependent energy decay
% over time and time/frequency inverse for impulse response calculation
% inputs:
% T = sweep duration in seconds
% f1 = start frequency in Hz
% f2 = end frequency in Hz
% silence = silence before and after sweep in seconds (default: 0)
% fs = sampling frequency (default: 44100)

if nargin < 5
    fs=44100;
end
if nargin < 4
    silence=0;
end
silence=silence*fs;

w1=2*pi*f1;
w2=2*pi*f2;
t=0:1/fs:(T*fs-1)/fs;
t=t';
K=T*w1/log(w2/w1);
L=T/log(w2/w1);
sweep=sin(K.*(exp(t./L)-1));

if sweep(end)>0
    t_end=find(sweep(end:-1:1)<0,1,'first');
end   
if sweep(end)<0
    t_end=find(sweep(end:-1:1)>0,1,'first');
   
end
t_end=length(sweep)-t_end;
sweep(t_end+1:end)=0;
sweep=[zeros(silence,1);sweep;zeros(silence,1)];
invsweep=sweep(length(sweep):-1:1).*exp(-t./L);
invsweep=invsweep/max(abs(invsweep));

Contact us at files@mathworks.com