# How can I plot frequency vs magnitude of wavelet transform?

I am running Morlet continuous wavelet transform. I have got wscalogram of signal and now I want to plot freq-magnitude like the following picture., but I don't know how to do it: I've used scal2freq MATLAB function to convert scales to pseudo frequencies. Also I have some frequencies in my signal that have a large damping ratio(4%) so they are not well visible in plot. How can I exaggerate these highly damped modes?

I am using MATLAB, here is my codes:

% Import the text4.txt to matlab workspace. and save it under name "data"
t=linspace(0,30,301);
Fs=ceil(inv(t(2)-t(1)));
x=data(:,4); % use x=data(:,3),x=data(:,5) too. first column is time,second is refrence
wname = 'morl';
scales = 1:1:256;
coefs = cwt(x,scales,wname,'lvlabs');
freq = scal2frq(scales,wname,1/Fs);
axis tight; xlabel('Seconds'); ylabel('Pseudo-Frequency (Hz)');
axis([0 30 0 1 0 60])
xlabel('Time'); ylabel('Frequency');
figure;
sc=wscalogram('image',coefs,'scales',freq,'ydata',x);
hold on


My current plot looks like this: • What form does your wavelet transform data take? Jul 30 '13 at 4:57
• Hi @JimClay! I am not sure if I understand your question. but if you mean what it looks like, its like the 2nd link which I maintained at the question. and I want a plot like 1st link. (2nd [myplot]) cubeupload.com/im/bSSlMI.jpg 1st[desired]) cubeupload.com/im/KbhGMI.jpg here is my signal <fileswap.com/dl/Lwf7n96fAt/test4.txt.html> here is my Mfile <fileswap.com/dl/gMrslBFAdb/mfile.txt.html> best regards.
– SAH
Jul 30 '13 at 7:35
• I am not really sure what your question is... Jul 30 '13 at 18:36
• Hi @user4619; Look at first plot. you see a plot[freq-magnitude] on the right side of the wavelet scalogram[which obtained by matlab]. second picture is my wavelet scalogram. but I don't know how to plot[freq-magnitude] like the right side of first plot. any help plz?
– SAH
Jul 30 '13 at 18:41
• @Electricman A spectrogram is not the same as a scalogram. If you are going a scalogram, there is no frequency VS time, only scale VS time. So which one are you doing exactly? Jul 30 '13 at 18:51

Modifying your code a little bit, but no major changes, and I get correct results either way. Use this template code here, and you should not see any problems. I get the correct results.

clear all;
t=linspace(0,30,301);
Fs = (inv(t(2)-t(1)));
x=randn(100,1);
wname = 'morl';
scales = 1:1:256;
chefs = cwt(x,scales,wname,'lvlabs');

freq = scal2frq(scales,wname,1/Fs);

figure;
coefsSquared = abs(coefs).^2;
imagesc(coefsSquared);
grid off;

%Pick one of the columsn to plot:
figure;
plot(coefsSquared(:,47))


To get the figure on the right hand side of the first image you put up, that is simply the time-slice spectrum. In other words, one column of your frequency-time matrix.

For example, we might get the following squared-coefficient matrix, in frequency vs. time: Let us then suppose we wish to look at the spectrum for the time-slice at column 47. Then, this is given here: Here, you then see the power of the coefficients, vs. frequency, for the time-slice corresponding to column 47.

• Thanks for modifying the code. But I didn't get an answer for my question yet.The question is How can I plot Freq-magnitude or scales-magnitude[no difference]. I want a plot like the right side of first picture.[it's in question]. thanks in advance
– SAH
Jul 30 '13 at 19:45
• @Electricman The plot on the right hand side is simply one column of your Frequency VS Time matrix. Jul 30 '13 at 19:55
• -@user4619 It's not Freq vs time, The time range is 0-20 and the frequency range is 0-2.5 but the right hand side plot is freq vs magnitude. I am not sure its exactly coefs or magnitude but obviously its proportional to cofes or cofes^2. tnx
– SAH
Jul 30 '13 at 20:03
• @Electricman Please see the edits. Is it clearer now? Jul 30 '13 at 20:10
• -@user4619 It works. Thanks for your answer. I put a little code at the end of mfile. and got the same plot as right hand side of the mentioned plot. cof2=abs(coefs).^2; cof2trans=cof2'; maxmods=max(cof2trans); figure; plot(maxmods,freq) axis([0 60 0 1]) Best regards
– SAH
Jul 30 '13 at 21:11

Continuous wavelet transform (CWT) is a method for time-scale analysis. Yes, you read it correctly, scale, not frequency. However, it is possible to map the scales to frequencies, and even quite easily. Since you are a MATLAB user, you will probably want to use this function, which does the following:

F = scal2frq(A,'wname',DELTA) returns the pseudo-frequencies corresponding to the scales given by A, the wavelet function 'wname' (see wavefun for more information) and the sampling period DELTA.

As you can read, the frequencies are not the real frequencies in the signal, but approximations. If you want the real frequencies, you should be using the short-time Fourier transform (STFT).

So, when should one use the CWT? As a general principle, wavelets work well when the signals are transient (i.e. have quick changes).

EDIT: haha, I don't know what I'm doing here. sorry :-D completely missed the point of your question. Just read the title....

• @wave your information is correct. But so what? I just want to have a plot like right side of the first picture. the freq vs magnitude. and it's OK if I get scales vs magnitude as long as I can use scal2freq.
– SAH
Jul 30 '13 at 19:27
• "If you want the real frequencies, you should be using the short-time Fourier transform (STFT)." Morlet wavelet has frequency in the same way as a Gaussian-windowed STFT has frequency. The "atoms" of both transforms are the same. Sep 6 '13 at 14:03

Not sure if you still need help...

If you want frequency vs. magnitude use a "mesh/surf" command to plot the coefficients.

Then change the orientation of the plot so that you have the result you seek. For this see the "view" command.

• Thanks, I solved that problem several months ago and published my results. But I will try your alternative next time.but, please move your answer to comment place. good luck. @asilva732
– SAH
Aug 25 '14 at 10:39