Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STFT Matlab code in the article #25

Open
whip123 opened this issue Mar 5, 2023 · 5 comments
Open

STFT Matlab code in the article #25

whip123 opened this issue Mar 5, 2023 · 5 comments

Comments

@whip123
Copy link

whip123 commented Mar 5, 2023

Hi, I am currently trying to replicate the comparison in the article. But I couldn't get the same result as the Benchmark results for synthetic data showed. Could you post the STFT code in the article here? Thanks a @fastlib @lschneiderbauer @felixdollack .
(URGENT)

@felixdollack
Copy link
Contributor

Hi @whip123,

I am not associated with this project.
Just having a personal interest in it.
You also posted commented here that you could not build the library for Matlab on Windows.
In case you managed, could you comment in the other issue how you managed?

Best,
Felix

@fastlib
Copy link
Owner

fastlib commented Mar 15, 2023

Dear @whip123,

The article in Nature Computational Science should have all the details about the parameters used for the STFT. Can you show me in which way you cannot match the benchmark results?

fastlib

@whip123
Copy link
Author

whip123 commented Mar 23, 2023

Dear @fastlib

For now, I couldn't normalize my result as shown in the article. Could you tell me how?
Below is my Matlab code to replicate the results in the article

tic
[s,f,t] = stft(signal,fs,Window=blackman(250,'period'),OverlapLength=200,FFTLength=512);
STFTtime = toc
sdb = mag2db(abs(s));
mesh(t,f,sdb);
cc = max(sdb(:))+[-50 0];
ax = gca;
ax.CLim = cc;
view(2)
ylim([0 120])
ylabel("Frequency (Hz)");
xlabel("Time (s)");
colorbar;
image

Thank you.
whip123

@fastlib
Copy link
Owner

fastlib commented Mar 24, 2023

We normalized every time-frequency matrix to a [0,1] range. As such, the power scale is transformed to an arbitary power unit that allows a fair comparison for the ridge extraction analysis we did subsequently. I hope this answers your question. For completeness I pasted the code below:

`function [res,ts,frqs] = stftwrapper(times,tstep,data,fs,f0,f1,tit,fftlength)

[s,freqs,t] = stft(data,fs,'Window',blackman(round(fs*0.5)),'OverlapLength',round(fs*0.40),'FFTLength',fftlength);

[v,s0]=min(abs(freqs-f0));
[v,s1]=min(abs(freqs-f1));

image(t,freqs(s0:s1,:),normalizeMatrix(abs(s(s0:s1,:))),"CDataMapping","direct")
res = normalizeMatrix(abs(s(s0:s1,:)));
set(gca, 'ydir', 'normal');
colormap jet;

ts = t;
frqs = freqs(s0:s1,:);

xlabel("Time (s)");
ylabel("Frequency (Hz)");

xticks(min(times+30):tstep:(max(times+30)))
xticklabels(min(times):tstep:(max(times)))

ttl = title(tit);
ttl.Units = 'Normalize'; 
ttl.FontSize = sp(6);
ttl.Position(1) = 0; % use negative values (ie, -0.1) to move further left
ttl.HorizontalAlignment = 'left';  
ttl.Color = 'white';

return`

@whip123
Copy link
Author

whip123 commented Mar 25, 2023

Hi @fastlib

Thanks for the code, could you give me all the parameters as well, such as fft length, f0, f1 and times.

Furthermore, I would also like to apologize for the mistakes in my previous post, as I found that I posted the wrong spectrogram after applying the code. Below shows the spectrogram I got after applying the code with 500ms Blackman window, and 400ms overlap.
image
However, in the spectrogram, there are 2 white lines, do u have any idea what I should change in the code? in order to get the same graph as the article shown

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants