r/scilab • • 7h ago

Update on where we're going...Starting a Xcos Thread while maintaining the present Data Science and Engineering Thread. Consider this post as Xcos Installment 1.

1 Upvotes

We'll about a month away from finishing up the Fourier Series and starting the next series "Sparsity and Compressed Sensing." I've been working ahead on the Data Science and Engineering Thread and already I'm at the end Chapter 8 and at the present pace, a once-a-week release, I have a year's worth of releases ready to go.

I'm wanting to get into Xcos since it's a major part of SciLab. I've been reviewing what's out there for Xcos demonstrations and I'm underwhelmed. The typical YouTube video is how to put a few blocks in the screen from the palette and run a first order and second order system simulation.

So far, I've found a good starter video "Xcos - quick and complete introduction" by "Automotive Engineering Explained" a hands-on tutorial on Xcos block diagram modeling and simulation, containing the following topics:

  1. What is Xcos ?
  2. Xcos environment
  3. How to launch Xcos
  4. Xcos Palette
  5. Xcos block
  6. Build an Xcos diagram
  7. Xcos simulation parameters
  8. Run simulation and visualize results

and:

GitHub - Foadsf/xcos-by-example: Xcos (Scilab) by example: generated, linted, simulated minimal working examples with diagrams and plots. CC BY-SA 4.0 · GitHub where this person has a number of examples that can be explored.

====================================================

I have not found a good "Simulation Course" that utilizes Simulink or Xcos extensively. Most seem to talk about simulation a lot without much of a lab. Personally, the general simulation course would interest me since I've done a lot of controls. If anyone has come across a good course, let me know. I've not looked at MIT offerings yet.

In the Controls courses, they mostly are doing the standard analysis (block diagram, signal flow graphs, stability, controllability, observability, Routh Hurwitz, root-locus, bode, etc) with a very short simulation section (similar to "by the way" you can simulate with Simulink or Xcos).

Right now, there are two YouTube ones I'm looking at 1) Brian Douglas's stuff on Controls and 2) Steve Brunton's Control Boot Camp (this one will be similar to where we're headed in the Data Science and Engineering Thread in Chapter 8).


r/scilab • • 15h ago

Data-Driven Science and Engineering Series - Installment 24 2D Transforms and Image Processing

1 Upvotes

In this edition he explores 2D FFT's and Image Compression.

Book Section 2.6 2D Transforms and Image Processing

YouTube Video on the subject:

https://www.youtube.com/watch?v=gGEBUdM0PVc&list=PLMrJAkhIeNNT_Xh3Oy0Y4LTj0Oxo8GqsC&index=32

SciLab Coding Wise: 2D fft (the hard way using fft and the easy way using fft2 - notice the calculation time difference), fftshift, image rescaling.

Output: Program Echo Only

"Data-Driven Science and Engineering - 2D FFT Analysis Example"

"2026-10-26 11:56:49.341"

Figure:

Code:

clear;
clc;
//close out all existing scf()s
close(winsid())

disp("Data-Driven Science and Engineering - 2D FFT Analysis Example",string(datetime()))

//Section 2.6 2D Transforms and Image Processing

//YouTube Video: https://www.youtube.com/watch?v=gGEBUdM0PVc&list=PLMrJAkhIeNNT_Xh3Oy0Y4LTj0Oxo8GqsC&index=32

// Function: rescaleToUint8
// Purpose : Rescale any numeric matrix to the range [0,255] and convert to uint8
function 
img8
=rescaleToUint8(
M
)
    
// Validate input
    if ~isreal(
M
) then
        error("Input must be a real-valued matrix.");
    end

    
// Handle constant matrix (avoid division by zero)
    if max(
M
) == min(
M
) then
        
img8
 = uint8(zeros(
M
)); 
// all pixels black
        return;
    end

    
// Normalize to [0,1]
    Mnorm = (
M
 - min(
M
)) / (max(
M
) - min(
M
));

    
// Scale to [0,255] and convert
    
img8
 = uint8(round(Mnorm * 255));
endfunction

//Use full file path to your unzipped data file...
A=imread('C:\Users\MattheW\Documents\eBooks\ScILabNotes\DataScience\CODE\CH01\dog.jpg');
B = rgb2gray(A);    
// Convert to grayscale image

scf()
clf
subplot(1,3,1)
//imagesc(B);         % Plot image
imshow(uint8(B));
title('Original in Gray Scale');

for j=1:size(B,1);  
// Compute row-wise FFT
    C(j,:) = fft(double(B(j,:)));
    Cshift(j,:) = fftshift(C(j,:));    
end

subplot(1,3,2)
img_rescaled = rescaleToUint8(log(abs(Cshift)+1)) 
//Need the "+1" to prevent log(0)=-inf issue
imshow(uint8(img_rescaled+1000))
xlabel(["Figure 2.25: Schematic of 2D FFT. The FFT is taken of each row, and then";...
"the FFT is taken of each column of the resulting transformed matrix."])
//imshow(uint8(log(abs(Cshift))))

for j=1:size(C,2);  
// Compute column-wise FFT
    D(:,j) = fft(C(:,j));
end

subplot(1,3,3)
img_rescaled = rescaleToUint8(fftshift(log(abs(D))))
imshow(uint8(img_rescaled))
//imshow(uint8(fftshift(log(abs(D)))))

scf()
D1 = fft2(double(B)); 
// Much more efficient to use fft2
img_rescaled = rescaleToUint8(fftshift(log(abs(D1))))
imshow(uint8(img_rescaled))