CWT matlab function [closed]

i'm trying to apply the cwt function from matlab in the first graph and from the different articles that i've read i should get something that shows different peaks to determine the location of damage, but all i'm getting is that spaghetti looking mess. is there a different approach to applying wavelet transform without using the built in function? thanks

closed as off-topic by Stanley Pawlukiewicz, MBaz, lennon310, jojek♦Mar 11 at 14:20

• This question does not appear to be about signal processing within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

• Spaghetti happens because of the complex attitude of some CWT, that you already managed with Fourier. – Laurent Duval Mar 7 at 9:04
• does this mean that applying cwt to this signal is not possible? – Stephen Lopez Mar 7 at 9:11
• That is possible, and possibly more informative than with Fourier, as the signal is not stationary. – Laurent Duval Mar 7 at 9:14
• your spaghetti is probably an artifact of your plot call, not the cwt – Stanley Pawlukiewicz Mar 8 at 2:17
• I'm voting to close this question as off-topic because the problem has to do with calling matlab’s plot function with complex values and not a problem with wavelets – Stanley Pawlukiewicz Mar 8 at 2:22

1 Answer

Trying to guess which signal you are analyzing, and the purpose, here is a demo, on a real signal, with half the Fourier spectrum, and the corresponding continuous wavelet transform scalogram.

Here, I suspect that the signal is too short (without further objectives) for FFT and CWT to yield interpretable results. The Matlab code is:

nsample = 64; % An odd number
timeSampling = 1/nsample;
time = (0:nsample-1)*timeSampling;
ratioSecondHalf = 20;
data = zeros(nsample,1);
data(1:nsample/2,1) = rand(nsample/2,1)-0.5;
data = medfilt1(data,5);
data(nsample/2+1:end,1) = rand(nsample/2,1)/ratioSecondHalf;

[fftR,fftAxe] = FFTR(data,timeSampling);

[cwtCoeff,cwfFreq] = cwt(data,1:64,'morl',timeSampling);

figure(1);clf
subplot(3,1,1)
plot(time,data,'x-');;axis tight
xlabel('Time (a. u.)')
ylabel('Amplitude (a. u.)')
subplot(3,1,2)
plot(fftAxe,fftR,'x-');axis tight
xlabel('Frequency (a. u.)')
ylabel('Amplitude (a. u.)')
subplot(3,1,3)
h=imagesc('XData',time,'YData',2*cwfFreq/pi,'CData',abs(cwtCoeff));axis tight
xlabel('Time (a. u.)')
ylabel('Frequency (a. u.)')


FFTR.m is obtained from here.

• i've also tried this on a longer signal but it still gave me spaghetti i think it's because it's non-stationary like you said. – Stephen Lopez Mar 7 at 13:29
• Abslute value is lacking somewhere – Laurent Duval Mar 7 at 15:39
• ANd the longer length is about interpretability, not spaghetti – Laurent Duval Mar 9 at 16:22
• i did it with absolute value and i got better results, no more spaghetti. – Stephen Lopez Mar 11 at 14:42
• Good, spaghetti arise from plotting complex values as 2D points (real+imaginary) – Laurent Duval Mar 11 at 15:40