Wavelet scattering display problem

2 views (last 30 days)
Dear All,
I have a problem with Scattergram, when I use wavelet scattering coefficients to plot the scattergram it displays like this:
but when I store the scattergam in data variable and try to plot the contour of it, the image is reversed and I lost the axis (time, frequency) as the following picture:
Here is the code and the signal :
fs =2000;
sf = waveletScattering('SignalLength',numel(pcg),...
'SamplingFrequency',fs);
[S,U] = scatteringTransform(sf,pcg);
% Normal case
figure,
scattergram(sf,U,'FilterBank',1);
% Abnormal case
img = scattergram(sf,U,'FilterBank',1);
contour(img)
if could anyone help with this problem, I'll appreciate it

Accepted Answer

Anavi Somani
Anavi Somani on 18 Jul 2023
Hi,
The issue you're facing with the reversed scattergram image and the lost axis when plotting the contour could be due to the difference in the default coordinate system used by `scattergram` and `contour` functions in MATLAB.
The `scattergram` function plots the scattergram with time on the x-axis and frequency on the y-axis by default. However, the `contour` function assumes that the first dimension of the image corresponds to the y-axis and the second dimension corresponds to the x-axis.
To address this issue and correctly plot the contour with the appropriate axis labels, you can modify the code as follows:
fs = 2000;
sf = waveletScattering('SignalLength', numel(pcg), 'SamplingFrequency', fs);
[S, U] = scatteringTransform(sf, pcg);
% Normal case
figure
scattergram(sf, U, 'FilterBank', 1);
% Abnormal case
img = scattergram(sf, U, 'FilterBank', 1);
contour(flipud(img), 'XData', sf{1}.time, 'YData', sf{1}.log2Scales)
xlabel('Time')
ylabel('Frequency')
In the modified code, the `flipud` function is used to flip the image vertically, aligning it with the expected orientation for the `contour` function. Additionally, the `XData` and `YData` parameters are provided to specify the correct axis labels for the contour plot.
By incorporating these changes, you should be able to plot the contour of the scattergram with the correct orientation and axis labels.
Hope it helps.
  2 Comments
Abdelhakim Souidi
Abdelhakim Souidi on 18 Jul 2023
Thank you for replying, indeed this function flip the image vertically.
I come up with other solution, it just based on picking up the centerfrequencies
t1 = linspace(0,size(pcg,1)/fs,size(img,2));
F =centerFrequencies(sf);
f = F{1,1};
figure,
contour(t1,f,img);
thank you

Sign in to comment.

More Answers (0)

Categories

Find more on Contour Plots in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!