function [st,t,f] = gst(timeseries,lamda,p,minfreq,maxfreq,samplingrate,freqsamplingrate)
% Returns the Stockwell Transform of the timeseries.
% Code by Robert Glenn Stockwell.
% DO NOT DISTRIBUTE
% BETA TEST ONLY
% Reference is "Localization of the Complex Spectrum: The S Transform"
% from IEEE Transactions on Signal Processing, vol. 44., number 4, April 1996, pages 998-1001.
%
%-------Inputs Needed------------------------------------------------
%
% *****All frequencies in (cycles/(time unit))!******
% "timeseries" - vector of data to be transformed
% “时间序列” - 要转换的数据向量
%-------Optional Inputs ------------------------------------------------
%
%"lamda and "p" are variables to contral Guass window(Default=1)
%"minfreq" is the minimum frequency in the ST result(Default=0)
%“minfreq”是ST结果中的最小频率(默认值= 0)
%"maxfreq" is the maximum frequency in the ST result (Default=Nyquist)
%“maxfreq”是ST结果中的最大频率(默认值=奈奎斯特)
%"samplingrate" is the time interval between samples (Default=1)
%“samplingrate”是采样间的时间间隔(默认值= 1)
%"freqsamplingrate" is the frequency-sampling interval you desire in the ST result (Default=1)
%“freqsamplingrate”是在ST结果中需要的频率采样间隔(默认值= 1)
%Passing a negative number will give the default ex. [s,t,f] = st(data,-1,-1,2,2)
%传递负数需要给出默认的前缀。 [s,t,f] = st(data,-1,-1,2,2)
%-------Outputs Returned------------------------------------------------
%
% st -a complex matrix containing the Stockwell transform.
% st - 包含Stockwell变换的复数矩阵。
% The rows of STOutput are the frequencies and the
% columns are the time values ie each column is
% the "local spectrum" for that point in time
%ST输出的行是频率,列是时间值,即每列是该时间点的“本地频谱”
% t - a vector containing the sampled times
% t - 包含采样时间的矢量
% f - a vector containing the sampled frequencies
% f - 包含采样频率的矢量
%--------Additional details-----------------------
% % There are several parameters immediately below that
% the user may change. They are:
%[verbose] if true prints out informational messages throughout the function.
% 如果true,则在整个函数中输出信息性消息。
%[removeedge] if true, removes a least squares fit parabola
% and puts a 5% hanning taper on the edges of the time series.
% This is usually a good idea.
% 如果true,则删除最小二乘拟合抛物线,并在时间序列的边缘放置5%汉宁锥度。
%[analytic_signal] if the timeseries is real-valued
% this takes the analytic signal and STs it.
% This is almost always a good idea.
% 如果时间序列是实数值,则需要分析信号和ST。
%[factor] the width factor of the localizing gaussian
% ie, a sinusoid of period 10 seconds has a
% gaussian window of width factor*10 seconds.
% I usually use factor=1, but sometimes factor = 3
% to get better frequency resolution.
% 定位高斯宽度因子即10秒周期的正弦曲线具有宽度因子* 10秒的高斯窗口。
% 我通常使用调节因子= 1,但有时调节因子= 3以获得更好的频率分辨率。
% Copyright (c) by Bob Stockwell
% $Revision: 1.2 $ $Date: 1997/07/08 $
% This is the S transform wrapper that holds default values for the function.
% 这是保存函数默认值的S变换组包。
TRUE = 1;
FALSE = 0;
%%% DEFAULT PARAMETERS [change these for your particular application]
%%% 默认参数[针对您的特定应用更改这些参数]
verbose = TRUE;
removeedge= FALSE;
analytic_signal = FALSE;
factor = 1;
%%% END of DEFAULT PARAMETERS
%默认参数结束
%%%START OF INPUT VARIABLE CHECK
% 输入变量检查开始
% First: make sure it is a valid time_series
% If not, return the help message
%首先:确保它是有效的time_series时间序列;如果不是,请返回帮助信息
if verbose ,disp(' '),end % i like a line left blank
%判断输入变量的个数
if nargin == 0
if verbose ,disp('No parameters inputted.'),end
st_help
t=0;st=-1;f=0;
return
end
% Change to column vector
% 更改为列向量
if size(timeseries,2) > size(timeseries,1)
timeseries=timeseries';
end
% Make sure it is a 1-dimensional array
if size(timeseries,2) > 1
error('Please enter a *vector* of data, not matrix')
return
elseif (size(timeseries)==[1 1]) == 1
error('Please enter a *vector* of data, not a scalar')
return
end
% use defaults for input variables
% 使用输入变量的默认值
if nargin == 1
lamda=1;
p=1;
minfreq = 0;
maxfreq = fix(length(timeseries)/2);
samplingrate=1;
freqsamplingrate=1;
elseif nargin == 2
p=1;
minfreq = 0;
maxfreq = fix(length(timeseries)/2);
samplingrate=1;
freqsamplingrate=1;
[ lamda,p,minfreq,maxfreq,samplingrate,freqsamplingrate] = check_input(lamda,p,minfreq,maxfreq,samplingrate,freqsamplingrate,verbose,timeseries);
elseif nargin == 3
minfreq = 0;
maxfreq = fix(length(timeseries)/2);
samplingrate=1;
freqsamplingrate=1;
[ lamda,p,minfreq,maxfreq,samplingrate,freqsamplingrate] = check_input(lamda,p,minfreq,maxfreq,samplingrate,freqsamplingrate,verbose,timeseries);
elseif nargin==4
maxfreq = fix(length(timeseries)/2);
samplingrate=1;
freqsamplingrate=1;
[ lamda,p,minfreq,maxfreq,samplingrate,freqsamplingrate] = check_input(lamda,p,minfreq,maxfreq,samplingrate,freqsamplingrate,verbose,timeseries);
elseif nargin==5
samplingrate=1;
freqsamplingrate=1;
[ lamda,p,minfreq,maxfreq,samplingrate,freqsamplingrate] = check_input(lamda,p,minfreq,maxfreq,samplingrate,freqsamplingrate,verbose,timeseries);
elseif nargin==6
freqsamplingrate=1;
[ lamda,p,minfreq,maxfreq,samplingrate,freqsamplingrate] = check_input(lamda,p,minfreq,maxfreq,samplingrate,freqsamplingrate,verbose,timeseries);
elseif nargin == 7
[ lamda,p,minfreq,maxfreq,samplingrate,freqsamplingrate] = check_input(lamda,p,minfreq,maxfreq,samplingrate,freqsamplingrate,verbose,timeseries);
else
if verbose,disp('Error in input arguments: using defaults'),end
lamda=1;
p=1;
minfreq = 0;
maxfreq = fix(length(timeseries)/2);
samplingrate=1;
freqsamplingrate=1;
end
if verbose
fprintf('Lamda=%d\n',lamda)
fprintf('P=%d\n',p)
fprintf('Minfreq = %d\n',minfreq)
fprintf('Maxfreq = %d\n',maxfreq)
fprintf('Sampling Rate (time domain) = %d\n',samplingrate)
fprintf('Sampling Rate (freq. domain) = %d\n',freqsamplingrate)
fprintf('The length of the timeseries is %d points\n',length(timeseries))
disp(' ')
end
%END OF INPUT VARIABLE CHECK
%输入变量检查结束
% If \“硬连线”minfreq&maxfreq&samplingrate&freqsamplingrate在这里做
% calculate the sampled time and frequency values from the two sampling rates
% 根据两个采样率计算采样的时间和频率值
t = (0:length(timeseries)-1)*samplingrate;
spe_nelements =ceil((maxfreq - minfreq+1)/freqsamplingrate) ;
f = (minfreq + [0:spe_nelements-1]*freqsamplingrate)/(samplingrate*length(timeseries));
if verbose,fprintf('The number of frequency voices is %d\n',spe_nelements),end
% The actual S Transform function is here:
% 实际的S变换函数在这里:
st = strans(timeseries,lamda,p,minfreq,maxfreq,samplingrate,freqsamplingrate,verbose,removeedge,analytic_signal,factor);
% this function is below, thus nicely encapsulated
% 这个函数在下面,因此很好的封装
%WRITE switch statement on nargout
%在nargout上写入开关语句
% if 0 then plot amplitude spectrum
% 如果是0,则绘制幅度谱
if nargout==0
if verbose,disp('Plotting pseudocolor image'),end
pcolor(t,f,abs(st))
end
%绘制伪彩色图
return
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
评论4