S变换介绍(附代码)

article/2025/9/12 5:02:08

1、S变换

        作为小波变换和短时傅里叶变换的继承和发展, S 变换采用高斯窗函数且窗宽与频率的倒数成正比,免去了窗函数的选择和改善了窗宽固定的缺陷,并且时频表示中各频率分量的相位谱与原始信号保持直接的联系,使其在 PQD 分析中可以采用更多的特征量,同时, S 变换提取的特征量对噪声不敏感。因此,在电能电能质量扰动、轴承故障诊断领域运用广泛。适用于非平稳信号的时频分析方法,其定义为:

            3177e7a707ee47b28ebc1bfbd9196fc0.png

                        ​​​​​​​        ​​​​​​​        ​​​​​​​     26cb5dbaa3c34a84ac5bd7fa7932491c.png

                 5303b218009f46709c1a2864d0b9546e.png

 2、S变换matlab代码

unction [st,t,f] = st(timeseries,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 ------------------------------------------------ 
% 
%"minfreq" is the minimum frequency in the ST result(Default=0) 
%"maxfreq" is the maximum frequency in the ST result (Default=Nyquist) 
%"samplingrate" is the time interval between samples (Default=1) 
%"freqsamplingrate" is the frequency-sampling interval you desire in the ST result (Default=1) 
%Passing a negative number will give the default ex.  [s,t,f] = st(data,-1,-1,2,2) 
%-------Outputs Returned------------------------------------------------ 
% 
% st     -a complex matrix containing the Stockwell transform.  
%			 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 
%  t      - a vector containing the sampled times 
%  f      - a vector containing the sampled frequencies 
%--------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. 
%[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. 
%[analytic_signal]  if the timeseries is real-valued 
%                      this takes the analytic signal and STs it. 
%                      This is almost always a good idea. 
%[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. 
%   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. 
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 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 minfreq = 0; maxfreq = fix(length(timeseries)/2); samplingrate=1; freqsamplingrate=1; 
elseif nargin==2 maxfreq = fix(length(timeseries)/2); samplingrate=1; freqsamplingrate=1; [ minfreq,maxfreq,samplingrate,freqsamplingrate] =  check_input(minfreq,maxfreq,samplingrate,freqsamplingrate,verbose,timeseries); 
elseif nargin==3  samplingrate=1; freqsamplingrate=1; [ minfreq,maxfreq,samplingrate,freqsamplingrate] =  check_input(minfreq,maxfreq,samplingrate,freqsamplingrate,verbose,timeseries); 
elseif nargin==4    freqsamplingrate=1; [ minfreq,maxfreq,samplingrate,freqsamplingrate] =  check_input(minfreq,maxfreq,samplingrate,freqsamplingrate,verbose,timeseries); 
elseif nargin == 5 [ minfreq,maxfreq,samplingrate,freqsamplingrate] =  check_input(minfreq,maxfreq,samplingrate,freqsamplingrate,verbose,timeseries); 
else       if verbose disp('Error in input arguments: using defaults'),end minfreq = 0; maxfreq = fix(length(timeseries)/2); samplingrate=1; freqsamplingrate=1; 
end 
if verbose  disp(sprintf('Minfreq = %d',minfreq)) disp(sprintf('Maxfreq = %d',maxfreq)) disp(sprintf('Sampling Rate (time   domain) = %d',samplingrate)) disp(sprintf('Sampling Rate (freq.  domain) = %d',freqsamplingrate)) disp(sprintf('The length of the timeseries is %d points',length(timeseries))) disp(' ') 
end 
%END OF INPUT VARIABLE CHECK % If you want to "hardwire" minfreq & maxfreq & samplingrate & freqsamplingrate do it here % 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 disp(sprintf('The number of frequency voices is %d',spe_nelements)),end % The actual S Transform function is here: 
st = strans(timeseries,minfreq,maxfreq,samplingrate,freqsamplingrate,verbose,removeedge,analytic_signal,factor);  
% this function is below, thus nicely encapsulated %WRITE switch statement on nargout 
% if 0 then plot amplitude spectrum 
if nargout==0  if verbose disp('Plotting pseudocolor image'),end pcolor(t,f,abs(st)) 
end return %^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function st = strans(timeseries,minfreq,maxfreq,samplingrate,freqsamplingrate,verbose,removeedge,analytic_signal,factor);  
% Returns the Stockwell Transform, STOutput, of the time-series 
% Code by R.G. Stockwell. 
% 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 Returned------------------------------------------------ 
%         - are all taken care of in the wrapper function above 
% 
%-------Outputs Returned------------------------------------------------ 
% 
%	ST    -a complex matrix containing the Stockwell transform. 
%			 The rows of STOutput are the frequencies and the 
%			 columns are the time values 
% 
% 
%----------------------------------------------------------------------- % Compute the length of the data. 
n=length(timeseries); 
original = timeseries; 
if removeedge if verbose disp('Removing trend with polynomial fit'),end ind = [0:n-1]'; r = polyfit(ind,timeseries,2); fit = polyval(r,ind) ; timeseries = timeseries - fit; if verbose disp('Removing edges with 5% hanning taper'),end sh_len = floor(length(timeseries)/10); wn = hanning(sh_len); if(sh_len==0) sh_len=length(timeseries); wn = 1&[1:sh_len]; end % make sure wn is a column vector, because timeseries is if size(wn,2) > size(wn,1) wn=wn';	 end timeseries(1:floor(sh_len/2),1) = timeseries(1:floor(sh_len/2),1).*wn(1:floor(sh_len/2),1); timeseries(length(timeseries)-floor(sh_len/2):n,1) = timeseries(length(timeseries)-floor(sh_len/2):n,1).*wn(sh_len-floor(sh_len/2):sh_len,1); end % If vector is real, do the analytic signal  if analytic_signal if verbose disp('Calculating analytic signal (using Hilbert transform)'),end % this version of the hilbert transform is different than hilbert.m %  This is correct! ts_spe = fft(real(timeseries)); h = [1; 2*ones(fix((n-1)/2),1); ones(1-rem(n,2),1); zeros(fix((n-1)/2),1)]; ts_spe(:) = ts_spe.*h(:); timeseries = ifft(ts_spe); 
end   % Compute FFT's 
tic;vector_fft=fft(timeseries);tim_est=toc; 
vector_fft=[vector_fft,vector_fft]; 
tim_est = tim_est*ceil((maxfreq - minfreq+1)/freqsamplingrate)   ; 
if verbose disp(sprintf('Estimated time is %f',tim_est)),end % Preallocate the STOutput matrix 
st=zeros(ceil((maxfreq - minfreq+1)/freqsamplingrate),n); 
% Compute the mean 
% Compute S-transform value for 1 ... ceil(n/2+1)-1 frequency points 
if verbose disp('Calculating S transform...'),end 
if minfreq == 0 st(1,:) = mean(timeseries)*(1&[1:1:n]); 
else st(1,:)=ifft(vector_fft(minfreq+1:minfreq+n).*g_window(n,minfreq,factor)); 
end %the actual calculation of the ST 
% Start loop to increment the frequency point 
for banana=freqsamplingrate:freqsamplingrate:(maxfreq-minfreq) st(banana/freqsamplingrate+1,:)=ifft(vector_fft(minfreq+banana+1:minfreq+banana+n).*g_window(n,minfreq+banana,factor)); 
end   % a fruit loop!   aaaaa ha ha ha ha ha ha ha ha ha ha 
% End loop to increment the frequency point 
if verbose disp('Finished Calculation'),end %%% end strans function %------------------------------------------------------------------------ 
function gauss=g_window(length,freq,factor) % Function to compute the Gaussion window for  
% function Stransform. g_window is used by function 
% Stransform. Programmed by Eric Tittley 
% 
%-----Inputs Needed-------------------------- 
% 
%	length-the length of the Gaussian window 
% 
%	freq-the frequency at which to evaluate 
%		  the window. 
%	factor- the window-width factor 
% 
%-----Outputs Returned-------------------------- 
% 
%	gauss-The Gaussian window 
% vector(1,:)=[0:length-1]; 
vector(2,:)=[-length:-1]; 
vector=vector.^2;     
vector=vector*(-factor*2*pi^2/freq^2); 
% Compute the Gaussion window 
gauss=sum(exp(vector)); %----------------------------------------------------------------------- %^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^% 
function [ minfreq,maxfreq,samplingrate,freqsamplingrate] =  check_input(minfreq,maxfreq,samplingrate,freqsamplingrate,verbose,timeseries) 
% this checks numbers, and replaces them with defaults if invalid % if the parameters are passed as an array, put them into the appropriate variables 
s = size(minfreq); 
l = max(s); 
if l > 1   if verbose disp('Array of inputs accepted.'),end temp=minfreq; minfreq = temp(1);; if l > 1  maxfreq = temp(2);,end; if l > 2  samplingrate = temp(3);,end; if l > 3  freqsamplingrate = temp(4);,end; if l > 4   if verbose disp('Ignoring extra input parameters.'),end end; end       if minfreq < 0 | minfreq > fix(length(timeseries)/2); minfreq = 0; if verbose disp('Minfreq < 0 or > Nyquist. Setting minfreq = 0.'),end end if maxfreq > length(timeseries)/2  | maxfreq < 0  maxfreq = fix(length(timeseries)/2); if verbose disp(sprintf('Maxfreq < 0 or > Nyquist. Setting maxfreq = %d',maxfreq)),end end if minfreq > maxfreq  temporary = minfreq; minfreq = maxfreq; maxfreq = temporary; clear temporary; if verbose disp('Swapping maxfreq <=> minfreq.'),end end if samplingrate <0 samplingrate = abs(samplingrate); if verbose disp('Samplingrate <0. Setting samplingrate to its absolute value.'),end end if freqsamplingrate < 0   % check 'what if freqsamplingrate > maxfreq - minfreq' case freqsamplingrate = abs(freqsamplingrate); if verbose disp('Frequency Samplingrate negative, taking absolute value'),end end % bloody odd how you don't end a function %^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^% 
function st_help disp(' ') disp('st()  HELP COMMAND') disp('st() returns  - 1 or an error message if it fails') disp('USAGE::    [localspectra,timevector,freqvector] = st(timeseries)') disp('NOTE::   The function st() sets default parameters then calls the function strans()') disp(' ')   disp('You can call strans() directly and pass the following parameters') disp(' **** Warning!  These inputs are not checked if strans() is called directly!! ****') disp('USAGE::  localspectra = strans(timeseries,minfreq,maxfreq,samplingrate,freqsamplingrate,verbose,removeedge,analytic_signal,factor) ') disp(' ') disp('Default parameters (available in st.m)') disp('VERBOSE          - prints out informational messages throughout the function.') disp('REMOVEEDGE       - removes the edge with a 5% taper, and takes') disp('FACTOR           -  the width factor of the localizing gaussian') disp('                    ie, a sinusoid of period 10 seconds has a ') disp('                    gaussian window of width factor*10 seconds.') disp('                    I usually use factor=1, but sometimes factor = 3') disp('                    to get better frequency resolution.') disp(' ') disp('Default input variables') disp('MINFREQ           - the lowest frequency in the ST result(Default=0)') disp('MAXFREQ           - the highest frequency in the ST result (Default=nyquist') disp('SAMPLINGRATE      - the time interval between successive data points (Default = 1)') disp('FREQSAMPLINGRATE  - the number of frequencies between samples in the ST results') % end of st_help procedure    

 代码引用来源IEEE Transactions on Signal Processing, vol. 44., number 4, April 1996, pages 998-1001. 

 

 


http://chatgpt.dhexx.cn/article/JABOwACH.shtml

相关文章

S(Stockwell)变换的Matlab代码

S变换的Matlab代码 S变换简介Stockwell版S变换程序Dash版S变换程序博主自己编写的S变换主函数仿真结果 S变换简介 S变换&#xff0c;又称为Stockwell变换&#xff0c;由R. G. Stockwell于1996年提出。具体的定义如下&#xff1a; S变换在傅里叶域的表示形式为&#xff1a; 离…

如何进行支付功能的测试

非现金支付时代&#xff0c;非现金支付已经成为了生活不可或缺的一部分&#xff0c;我们只需要一台手机便可走遍全国各地&#xff08;前提是支付宝&#xff0c;微信有钱<00>&#xff09;,那么作为测试人员&#xff0c;支付测试也是非常重要的一环&#xff0c;那么下面我就…

Wireshark对京东网站进行抓包

Wireshark对京东网站进行抓包 一、首先获取京东IP地址 二、写捕获器筛选条件抓包 1、设置捕获过滤器的host为自己主机IP和目的地址IP 开始抓包 在浏览器中打开京东&#xff0c;点击京东上物品信息&#xff0c;Wireshark就会抓取 抓包结束&#xff0c;保存pcap文件。 解析出cs…

支付宝、京东支付场景之策略模式实战

我是「猿码天地」&#xff0c;一个热爱技术、热爱编程的IT猿。技术是开源的&#xff0c;知识是共享的&#xff01; 写作是对自己学习的总结和记录&#xff0c;如果您对 Java、分布式、微服务、中间件、Spring Boot、Spring Cloud等技术感兴趣&#xff0c;可以关注我的动态&…

支付安全不能说的那些事

原文链接&#xff1a;https://www.inforsec.org/wp/?p1759 在线支付已经走进每个人的生活。抢红包、网上购物、生活缴费等服务中处处都有在线支付的身影。但是在线支付体系暴露过许多次安全问题&#xff0c;黑客利用在线支付的漏洞可以悄无声息的免费清空购物车等&#xff0c…

京东商品接口加解密算法解析

最近,闲来没事,打开看了一下京东图书的热销榜,想通过接口查看下它接口的加密方式,于是直接打开了M站的地址:https://m.jd.com/,然后打开搜索页面,如下图。 打开页面,打开开发者工具,往下滑动鼠标,获取接口地址。 解析一下接口,接口返回值跟没什么特殊说明,首尾加…

支付宝、财付通、网银、百度钱包、京东钱包接口费率

在集成支付功能时&#xff0c;遇到了付款方式接口选择的问题&#xff0c;于是对支付宝&#xff0c;财付通&#xff0c;PayPal&#xff0c;网银在线&#xff0c;快钱有了具体的认识&#xff0c;并分享出来。 支付渠道费用&#xff08;2016&#xff09; 渠道名称接入费交易手续费…

手把手教学京东api接口全部操作过程

jd.readme接入文档item_get获得JD商品详情item_search按关键字搜索商品item_search_img按图搜索京东商品&#xff08;拍立淘&#xff09;item_search_shop获得店铺的所有商品item_history_price获取商品历史价格信息item_recommend获取推荐商品列表upload_img上传图片到JDitem_…

京东APP下单接口调用

首先声明本人对于以下研究仅出于学习目的&#xff0c;不存在任何商业化行为。 通过京东app的api调用下单接口直接下单需要做一下两步&#xff1a; 签名&#xff1a;京东app的每一个接口都会带上sign参数&#xff0c;值是由body&#xff0c;st&#xff0c;sv&#xff0c;clien…

6.0 增加京东支付

给系统&#xff08;只适合版本6.0&#xff09;增加京东支付&#xff0c;系统原本是没有京东支付&#xff0c; 1、先在met_pay_config表中&#xff0c;增加京东支付参数&#xff0c;7京东支付 2、在系统中&#xff0c;浏览器在手机状态下增加京东支付 路径&#xff1a;\app\sy…

uniapp 让支付触手可及,封装了微信支付、QQ支付、支付宝支付、京东支付、银联支付常用的支付方式以及各种常用的接口

下载地址 https://gitee.com/zscat/mallplus 1.uniapp 接入各种h5支付 // 用户点击支付方式处理async toPayHandler(code) {let params = {orderId:this.orderId};let data = {payment_code: code,payment_type: this.type}data[orderId] = (this.type == 1 || this.type == …

RN对接京东支付sdk(IOS)

京东支付IOS接入说明文档 1、根据 京东支付IOS接入说明文档 集成sdk依赖的framework&#xff0c;配置相关的内容&#xff08;xcode 需要配置签名&#xff09; 2、在ios 下封装调用sdk的方法 JDPayManager.h // // JDPayManager.h // b2bapp // // Created by edz on 2021/…

Ecshop小京东支付插件【小京东个人支付宝即时到帐支付插件支持PC电脑版+手机版】

商之翼建立了一整套以标准化电商软件为基础的"一站式"全网营销电商解决方案。包括基于不同运维模式的B2B2B2C、B2B2C、B2C等被企业用户广泛使用的电商解决方案&#xff0c;还包括基于生鲜、农村、汽车、商超百货、建材、母婴、酒行业、跨境、社区等具体解决方案&…

京东支付逻辑存在不安全因素

写在前面的话: 写本文只想引起足够重视,不管是开发还是用户; 关于本文提到问题也提交给京东官方,希望他们能重视. 同时也希望看到本文的用户多一个心眼 希望大家都不要达到以下的全部假设; --------------------------- 以下测试完成于2015-09-08日; 测试条件与步骤: 一手机…

京东支付SDK重构设计与实现

背景 众所周知&#xff0c;软件开发效率、维护成本与自身复杂度成正比&#xff0c;而客户端软件复杂度则主要体现在业务规模上。 京东支付Android SDK从2015年启动以来&#xff0c;已历经五个春秋&#xff0c;如今发展到纯支付业务代码7.5W行的规模&#xff08;不含支付团队内…

php支付接口要改动的参数,京东支付接口2.0PHP集成遇到的一些问题:所有参数必须是string!...

最近发现京东的支付接口升级了&#xff0c;原来的接口以及不一样了&#xff0c;就花了点时间做了升级&#xff0c;但是遇到了一些很基础很二的问题&#xff0c;之前的时候接口跳转通知是get方式的&#xff0c;用在原来的支付驱动上面很正常&#xff0c;但是2.0的接口就没法正常…

京东支付接口

官方文档&#xff1a;http://payapi.jd.com/docList.html?methodName0# 一、本地测试(用官方自带参数测试) 1、下载官方接口文件: 京东支付PC&H5接口文档>>京东支付2.0-PHP 2、测试&#xff0c;把“京东支付2.0-PHP”解压出来的文件放到PHP环境中&#xff0c;什…

RN对接京东支付sdk(Android)

京东支付Android接入说明文档 1、根据 京东支付Android接入说明文档 集成sdk依赖的jar包&#xff0c;配置相关的内容&#xff08;主要根据文档一步一步配置就行&#xff0c;这里就不细说了&#xff0c;本章主要是关于使用RN调用sdk&#xff09; 2、在../android/app/src/java …

京东支付功能流程

1&#xff1a;目前市场上支付API的第三方很多&#xff0c;主流的接口有 支付宝&#xff0c;微信&#xff0c;京东&#xff0c;云闪付&#xff0c;银联 等等 主要包含 付款码支付 &#xff0c; JSAPI支付&#xff0c; APP支付&#xff0c;H5支付 &#xff0c; 小程序支付&…

微信公众账号自动回复小程序链接

<a data-miniprogram-appid"appid" data-miniprogram-path"路径" href"可以不写">小程序</a>效果图 文章引用于&#xff1a; http://dy.163.com/v2/article/detail/DR1H8P840511AOT5.html