0
$\begingroup$

I'm trying to build my own code implementation for Continuous Wavelet Fourier Transform. But when I compare the time-frequency plot created with my function with time-frequency plot created with the Matlab function, it seems time reversed.

x=signal;
N=length(x);

ff=[14:1:29]; % frequency to analize
W=zeros(ff(end)-ff(1),N); % build matrix to insert CWT
m=1;

for i=1:length(ff)
f=ff(i); %frequency

osc=7.5;  % Morlet Factor   These are the wavelet parameters
sigmaf=f/osc % Frequency standard deviation
sigmat=1/(2*pi*sigmaf) % Time standard deviation

t=[-N/2:N/2-1];
A=1/sqrt(sigmat*sqrt(pi));
g=A*exp(1i*2*pi*f*t/fs).*exp(-(t/fs).^2/(2*(sigmat.^2))); % Morlet function

gconj=conj(g); %Take the conjugate 
wavf=fft(gconj,N); %Compute the  morlet fft
xf=fft(x,N); %Compute the signal fft
T=xf.*(wavf);  % Product of signal with morlet
W(m,:)=ifft(T,N); %Take the iift and add it in the matrix
m=m+1;
end

To visualize the plot

imagesc(time,ff,abs(W).^2)
set(gca,'YDir','normal')

This is the CWT plot

enter image description here

If I use the ctwt function of Matlab

fmin=14;
fmax=29;
MorletFourierFactor = 4*pi/(6+sqrt(2+6^2));
s0=1/(MorletFourierFactor*fmax);
Ns=50;
ds=1/(Ns-1)*log2(fmax/fmin);
wname = 'morl';
SCA = {s0,ds,Ns};
zpd='zpd';
dt=1/EEG.srate;
cwtsig = cwtft({x,dt},'scales',SCA,'wavelet',wname);
Scales = cwtsig.scales.*MorletFourierFactor;
Freq = 1./Scales;
figure
imagesc(times,[],abs(cwtsig.cfs).^2);

I got enter image description here enter image description here

They are really similar but they are time reversed, and i have no idea. Thank you in advance

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.