Clear Filters
Clear Filters

How to use Dash code to get stockwell transform result?

8 views (last 30 days)
Hello,
I am trying to use Dash code to out put the grouph of Stockwell transform but I am quite confused of the variable f.
The code shows here
function ST=stran(h)
% Compute S-Transform without for loops
%%% Coded by Kalyan S. Dash %%%
%%% IIT Bhubaneswar, India %%%
[~,N]=size(h); % h is a 1xN one-dimensional series
nhaf=fix(N/2);
odvn=1;
if nhaf*2==N;
odvn=0;
end
f=[0:nhaf -nhaf+1-odvn:-1]/N;
Hft=fft(h);
%Compute all frequency domain Gaussians as one matrix
invfk=[1./f(2:nhaf+1)]';
W=2*pi*repmat(f,nhaf,1).*repmat(invfk,1,N);
G=exp((-W.^2)/2); %Gaussian in freq domain
% End of frequency domain Gaussian computation
% Compute Toeplitz matrix with the shifted fft(h)
HW=toeplitz(Hft(1:nhaf+1)',Hft);
% Exclude the first row, corresponding to zero frequency
HW=[HW(2:nhaf+1,:)];
% Compute Stockwell Transform
ST=ifft(HW.*G,[],2); %Compute voice
%Add the zero freq row
st0=mean(h)*ones(1,N);
ST=[st0;ST];
end
Can anyone explain what is f is and why I always got a zero value when analysis the audio file (f=[0:nhaf -nhaf+1-odvn:-1]/N;)? Thank you so much!

Accepted Answer

Abhimenyu
Abhimenyu on 8 Dec 2023
Hi Jingyi,
I understand that you want to gain more information about the variable “f” used in the code of Stockwell transformation provided by you. The Stockwell transform (ST) is a method of time-frequency analysis that provides frequency-dependent resolution and preserves the phase information of the signal.
The variable f is a vector of normalized frequencies, ranging from 0 to 0.5 for the positive frequencies and from -0.5 to -1/N for the negative frequencies, where N is the length of the signal. The variable f is used to construct the frequency domain Gaussian windows that are applied to the Fourier transform of the signal. The expression f= [0:nhaf -nhaf+1-odvn:-1]/N constructs a symmetric frequency axis around 0 that ranges from 0 to nhaf and then from -nhaf+1-odvnto -1. Here, “nhaf” is the half-length of the input signal, “odvn” is a variable that is set to 1 if the length of the input signal is odd, and 0 if it's even, and “N” is the length of the input signal.
The frequency axis is a crucial parameter that affects the results of the transform. If you are getting a zero value when analysing an audio file, it might be because the frequency axis is not suitable for the audio signal.
One possible reason is that the frequency axis is normalized by the length of the input signal, which means that the frequency resolution is dependent on the signal length. For example, if the signal length is 1000 samples, then the frequency resolution is 0.001, which might be too coarse for some audio signals. On the other hand, if the signal length is 100000 samples, then the frequency resolution is 0.00001, which might be too fine for some audio signals.
Another possible reason is that the frequency axis is symmetric around 0, which means that it includes both positive and negative frequencies. However, for real-valued signals, such as audio signals, the negative frequencies are redundant and can be ignored. Therefore, only the positive frequencies for the Stockwell Transform are to be used, which would also reduce the computational cost and memory usage.
The below mentioned suggestions can improve the performance of the Stockwell Transform for the audio data:
  • The frequency axis can be constructed in a different way. For example, a logarithmic scale for the frequency axis can be used, which would provide better resolution for low frequencies and less resolution for high frequencies.
  • Alternatively, a linear scale for the frequency axis can be used, but specification of the minimum and maximum frequencies of interest is required, rather than using the entire range from 0 to 0.5.
  • Using only the positive frequencies for the frequency axis and discarding the negative frequencies can also be helpful.
I hope this helps to resolve the query.
Thanks,
Abhimenyu
  1 Comment
Jingyi Yuan
Jingyi Yuan on 12 Dec 2023
Hello Abhimenyu,
Thank you so much for your reply! I tried this a year ago, and found the biggest problem for Stockwell transform is always exceed my memonery usage, and for most of time I can only transform a 3 seconds long ECG data. Your reply clearly explained why this happened and give me a way to solve the problem. Really appreciate for your answer!
All the best
Jingyi

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!