fastlib / fCWT

The fast Continuous Wavelet Transform (fCWT) is a library for fast calculation of CWT.
Apache License 2.0
263 stars 53 forks source link

Complex morelet wavelet of the eeg experiment in the article #40

Closed whip123 closed 1 year ago

whip123 commented 1 year ago

Hi @fastlib @felixdollack @lschneiderbauer

I am a newbie in signal processing. Based on the article, the cwt and fcwt in the eeg experiments are using complex morlet wavelet with a sigma value of 20 and I understand that the sigma parameters or number of cycles of a morlet wavelet is used to tune the time-frequency resolution tradeoff. Therefore, im currently trying to tune the parameters of sigma for morlet wavelet in CWT. However, i found that the cwt function in matlab 2023b only support the default analytical morelet wavelet "amor" and is unable to tune the sigma value. Hence, would like to ask how did u guys tune the sigma parameters of the morlet wavelet in cwt function of matlab and how do i set the fCWT in matlab to use complex morelet wavelet.

Could you show me the Matlab code of the eeg experiment in the article if possible?

Thanks in advance and sorry if this is a dumb quetion

fastlib commented 1 year ago

Hi Whip123,

In the article I used the Morse wavelet to mimic the Morlet Wavelet as close as possible:

[wt,freqs] = cwt(data,'morse',fs,'FrequencyLimits',[f0 f1],'VoicesPerOctave',4,'WaveletParameters',[floor(bandwidth/40) bandwidth]);
image(abs(wt),"CDataMapping","scaled")

where fs is the sample frequency, f0 and f1 are the start and end of the frequency range, respectively, and bandwidth the sigma.

Does this answer your question?

whip123 commented 1 year ago

Hi fastlib,

Yeah, the comment is immensely helpful.

However, I am still a bit confused about how did you determine the parameters of the Morse Wavelet will have the same response as the Morlet Wavelet?

Bandwidth = 20

[wt,cwtf] = cwt(signal,'morse',fs,'FrequencyLimits',[0.25 20],'VoicesPerOctave',48,'WaveletParameters',[floor(bandwidth/40) bandwidth]);

Furthermore, just want to make sure that, do you mean "bandwidth" is Sigma. Because after applying the code above, it shows an error msg "The ratio of the time-bandwidth parameter to the symmetry parameter has exceeded 40 "

fastlib commented 1 year ago

I cannot completely recall how I did it back in 2021, but I guess I plotted the impulse response of both wavelets and compared them by sight. Matlab has written an article about this comparison on their site as well: https://www.mathworks.com/help/wavelet/ref/cwtfilterbank.html#mw_c07efe81-5d89-4243-85ba-51ec1ccfb2ff

Furthermore, I guess bandwidth is not actually the sigma used in the paper, but a variable that's proportionate to sigma (in other words, it uses a different scaling). Trial and error, and plotting should get you to your bandwidth value.

whip123 commented 1 year ago

Understood. Thanks a lot for the clarification. Furthermore, I have a few more confusion that I would also like to ask for your expert opinions,

Currently, I'm trying to build CNN-based eeg emotion recognition model with CWT, STFT, and fCWT respectively, and compare the performance of each model with different methods. However, I found that the performance of STFT is better than CWT (the parameters of both methods have been tuned to the highest performance on CNN). Therefore, would like to ask, if it is possible that using STFT on a narrow band frequency signal such as the Alpha band of an eeg signal will provide better performance than CWT ?

fastlib commented 1 year ago

I have opened a new issue for your new question about the performance of fCWT vs STFT. I will close this comment.