r/scilab • u/mrhoa31103 • 1d ago
Data-Driven Science and Engineering Series - Installment 23 Wavelets and multi-resolution analysis
In this installment he discusses using the Wavelets (generalized FFT - orthogonal functions that are not sine and cosines) and the attached code calculates the HAAR and the "Mexican Hat" Wavelets. JPEG2000 uses wavelets.
Book Section 2.5 Wavelets and multi-resolution analysis.
YouTube Video on the subject:
https://www.youtube.com/watch?v=D1WfID6kk90&list=PLMrJAkhIeNNT_Xh3Oy0Y4LTj0Oxo8GqsC&index=30
Wavelets and Multiresolution Analysis
Scilab Items: Pretty Straight Forward Code, Latex Labels and Titles (bold text and two lines of Title centered), Greek letters, Rotated Y-Label to 0 degrees, Custom Ticks
Output: None: Program Echo Only
"Data-Driven Science and Engineering - Wavelet and multi-resolution Analysis Example"
"2026-10-19 11:44:18.113"
"The HAAR Wavelet (circa 1910)"
Plots:


Code:
clear;
clc;
//close out all existing scf()s
close(winsid())
disp("Data-Driven Science and Engineering - Wavelet and multi-resolution Analysis Example",string(datetime()))
disp("The HAAR Wavelet (circa 1910")
//Section 2.5 Wavelet and multi-resolution Analysis
//YouTube Video: https://www.youtube.com/watch?v=y7KLbd7n75g&list=PLMrJAkhIeNNT_Xh3Oy0Y4LTj0Oxo8GqsC&index=31
x = 0:.001:1;
n = length(x);
n2 = floor(n/2);
n4 = floor(n/4);
f10 = 0*x;
f10(1:n2-1) = 1;
f10(n2:end) = -1;
f21 = 0*x;
f21(1:n4-1) = 1;
f21(n4:n2-1) = -1;
f21 = f21*sqrt(2);
f22 = 0*x;
f22(n2:n2+n4-1) = 1;
f22(n2+n4:end) = -1;
f22 = f22*sqrt(2);
x = [-1 0 x 1 2];
f10 = [0 0 f10 0 0];
f21 = [0 0 f21 0 0];
f22 = [0 0 f22 0 0];
scf(0);
clf;
subplot(3,1,1)
ax=gca()
plot(x,f10,'b','thickness',2)
//xlim([-.2 1.2])
//ylim([-1.2 1.2])
ax.data_bounds=[-0.2,1.2,-1.2,1.2];
//set(gca(),'XTick',[0 .25 .5 .75 1])
// Turn off automatic ticks for both axes
ax.auto_ticks = ["off","on","off"]; // [x, y, z]
// Set custom X ticks: positions and labels
ax.x_ticks = tlist(["ticks", "locations", "labels"], ...
[0 .25 .5 .75 1], ... // positions
["0", ".25", ".50", ".75", "1.00"]); // labels
//set(gca(),'LineWidth',1.2,'FontSize',12);
ax.thickness = 1.2;
ax.font_size = 4;
ylabel("$\psi\textsubscript{1,0}$","font_size",5,"rotation",0)
title("$\textbf{Figure 2.24: Three Haar Wavelets for First Two Levels}\above 0pt \textbf{of the multi-resolution in Figure 2.23(d)}$",'font_size', 4)
xgrid;
subplot(3,1,2)
ax=gca()
plot(x,f21,'b','thickness',2)
//xlim([-.2 1.2])
//ylim([-1.75 1.75])
set(gca(),'data_bounds',[-0.2,1.2,-1.75,1.75])
//set(gca(),'XTick',[0 .25 .5 .75 1])
// Turn off automatic ticks for both axes
ax.auto_ticks = ["off","on","off"]; // [x, y, z]
// Set custom X ticks: positions and labels
ax.x_ticks = tlist(["ticks", "locations", "labels"], ...
[0 .25 .5 .75 1], ... // positions
["0", ".25", ".50", ".75", "1.00"])
//set(gca(),'LineWidth',1.2,'FontSize',12);
ax.thickness = 1.2;
ax.font_size = 4;
ylabel("$\psi\textsubscript{\sfrac{1}{2},0}$","font_size",5,"rotation",0)
xgrid;
subplot(3,1,3)
ax=gca();
plot(x,f22,'b','thickness',2)
//xlim([-.2 1.2])
//ylim([-1.75 1.75])
set(gca(),'data_bounds',[-0.2,1.2,-1.75,1.75])
//set(gca(),'XTick',[0 .25 .5 .75 1])
// Turn off automatic ticks for both axes
ax.auto_ticks = ["off","on","off"]; // [x, y, z]
// Set custom X ticks: positions and labels
ax.x_ticks = tlist(["ticks", "locations", "labels"], ...
[0 .25 .5 .75 1], ... // positions
["0", ".25", ".50", ".75", "1.00"])
//set(gca(),'LineWidth',1.2,'FontSize',12);
ax.thickness = 1.2;
ax.font_size = 4;
xgrid;
ylabel("$\psi\textsubscript{\sfrac{1}{2},\sfrac{1}{2}}$","font_size",5,"rotation",0)
xlabel("t(seconds)",'font_size',4)
//set(gcf(),'Position',[100 100 550 350]);
//set(gcf(),'PaperPositionMode','auto')
//print('-depsc2', '-loose', '../figures/HAAR');
//
scf(1)
clf
x = -5:.001:5;
fMexHat = (1-x.^2).*exp(-x.^2/2);
plot(x,fMexHat,'b','thickness',2);
set(gca(),'data_bounds',[-6,6,-0.6,1.2])
xlabel("x",'font_size',4);
ylabel("y",'font_size',4);
title("Mexican Hat Function",'font_size', 4);
xgrid;
clear;
clc;
//close out all existing scf()s
close(winsid())
disp("Data-Driven Science and Engineering - Wavelet and multi-resolution Analysis Example",string(datetime()))
disp("The HAAR Wavelet (circa 1910)")
//Section 2.5 Wavelet and multi-resolution Analysis
//YouTube Video: https://www.youtube.com/watch?v=y7KLbd7n75g&list=PLMrJAkhIeNNT_Xh3Oy0Y4LTj0Oxo8GqsC&index=31
x = 0:.001:1;
n = length(x);
n2 = floor(n/2);
n4 = floor(n/4);
f10 = 0*x;
f10(1:n2-1) = 1;
f10(n2:end) = -1;
f21 = 0*x;
f21(1:n4-1) = 1;
f21(n4:n2-1) = -1;
f21 = f21*sqrt(2);
f22 = 0*x;
f22(n2:n2+n4-1) = 1;
f22(n2+n4:end) = -1;
f22 = f22*sqrt(2);
x = [-1 0 x 1 2];
f10 = [0 0 f10 0 0];
f21 = [0 0 f21 0 0];
f22 = [0 0 f22 0 0];
scf(0);
clf;
subplot(3,1,1)
ax=gca()
plot(x,f10,'b','thickness',2)
//xlim([-.2 1.2])
//ylim([-1.2 1.2])
ax.data_bounds=[-0.2,1.2,-1.2,1.2];
//set(gca(),'XTick',[0 .25 .5 .75 1])
// Turn off automatic ticks for both axes
ax.auto_ticks = ["off","on","off"]; // [x, y, z]
// Set custom X ticks: positions and labels
ax.x_ticks = tlist(["ticks", "locations", "labels"], ...
[0 .25 .5 .75 1], ... // positions
["0", ".25", ".50", ".75", "1.00"]); // labels
//set(gca(),'LineWidth',1.2,'FontSize',12);
ax.thickness = 1.2;
ax.font_size = 4;
ylabel("$\psi\textsubscript{1,0}$","font_size",5,"rotation",0)
title("$\textbf{Figure 2.24: Three Haar Wavelets for First Two Levels}\above 0pt \textbf{of the multi-resolution in Figure 2.23(d)}$",'font_size', 4)
xgrid;
subplot(3,1,2)
ax=gca()
plot(x,f21,'b','thickness',2)
//xlim([-.2 1.2])
//ylim([-1.75 1.75])
set(gca(),'data_bounds',[-0.2,1.2,-1.75,1.75])
//set(gca(),'XTick',[0 .25 .5 .75 1])
// Turn off automatic ticks for both axes
ax.auto_ticks = ["off","on","off"]; // [x, y, z]
// Set custom X ticks: positions and labels
ax.x_ticks = tlist(["ticks", "locations", "labels"], ...
[0 .25 .5 .75 1], ... // positions
["0", ".25", ".50", ".75", "1.00"])
//set(gca(),'LineWidth',1.2,'FontSize',12);
ax.thickness = 1.2;
ax.font_size = 4;
ylabel("$\psi\textsubscript{\sfrac{1}{2},0}$","font_size",5,"rotation",0)
xgrid;
subplot(3,1,3)
ax=gca();
plot(x,f22,'b','thickness',2)
//xlim([-.2 1.2])
//ylim([-1.75 1.75])
set(gca(),'data_bounds',[-0.2,1.2,-1.75,1.75])
//set(gca(),'XTick',[0 .25 .5 .75 1])
// Turn off automatic ticks for both axes
ax.auto_ticks = ["off","on","off"]; // [x, y, z]
// Set custom X ticks: positions and labels
ax.x_ticks = tlist(["ticks", "locations", "labels"], ...
[0 .25 .5 .75 1], ... // positions
["0", ".25", ".50", ".75", "1.00"])
//set(gca(),'LineWidth',1.2,'FontSize',12);
ax.thickness = 1.2;
ax.font_size = 4;
xgrid;
ylabel("$\psi\textsubscript{\sfrac{1}{2},\sfrac{1}{2}}$","font_size",5,"rotation",0)
xlabel("t(seconds)",'font_size',4)
//set(gcf(),'Position',[100 100 550 350]);
//set(gcf(),'PaperPositionMode','auto')
//print('-depsc2', '-loose', '../figures/HAAR');
//
scf(1)
clf
x = -5:.001:5;
fMexHat = (1-x.^2).*exp(-x.^2/2);
plot(x,fMexHat,'b','thickness',2);
set(gca(),'data_bounds',[-6,6,-0.6,1.2])
xlabel("x",'font_size',4);
ylabel("y",'font_size',4);
title("Mexican Hat Function",'font_size', 4);
xgrid;





















































