Problem with identifying the entropy stabilization point in SSA for accurate signal decomposition.

1 view (last 30 days)
In Singular Spectrum Analysis (SSA), the goal is to decompose a signal into three main components:
  1. Trend: The overall trend of the signal, which represents long-term changes.
  2. Oscillations: Parts of the signal that change periodically, typically corresponding to medium-term variations.
  3. Noise: Parts of the signal that change randomly, usually representing noise or disturbances in the signal.
In this process, the signal is first transformed into a trajectory matrix, and then its components are extracted via Singular Value Decomposition (SVD).
Main Challenge:
  • After performing SVD and calculating the entropy of each component, we are looking for a point where the entropy stabilizes. This point is considered where additional components no longer contribute meaningful information to the model.
  • The problem is that the point of entropy stabilization is not being correctly identified, which results in an improper decomposition of the signal into the three components (trend, oscillations, and noise).
Question: Is there a method in MATLAB that can more accurately identify the point of entropy stabilization and correctly decompose the signal into trend, oscillations, and noise?
clc;
clear;
close all;
% Load the CSV file
[file, path] = uigetfile('*.csv', 'Please upload your CSV file:');
if isequal(file, 0)
error('No file selected.');
end
data = readtable(fullfile(path, file));
% Display available columns for the user to choose from
disp('Available columns in your dataset:');
disp(data.Properties.VariableNames');
column_name = input('Enter the column name you want to analyze: ', 's');
% Extract the signal (time series) from the chosen column
if ~any(strcmp(data.Properties.VariableNames, column_name))
error(['Column "', column_name, '" not found in the dataset.']);
end
signal = data.(column_name);
signal = signal(~isnan(signal)); % Drop NaN values
% SSA Functions
function X = trajectory_matrix(signal, window_length)
N = length(signal);
K = N - window_length + 1;
X = zeros(window_length, K);
for i = 1:K
X(:, i) = signal(i:i + window_length - 1);
end
end
function entropy = singular_entropy(S)
P = S / sum(S);
entropy = -sum(P .* log(P));
end
function reconstructed_signal = reconstruct_signal(U, S, V, indices, original_length)
reconstructed_trajectory = zeros(size(U, 1), size(V, 1));
for i = indices
reconstructed_trajectory = reconstructed_trajectory + S(i) * (U(:, i) * V(i, :));
end
[rows, cols] = size(reconstructed_trajectory);
signal_length = rows + cols - 1;
reconstructed_signal = zeros(signal_length, 1);
counts = zeros(signal_length, 1);
% Extracting anti-diagonals
for k = 1:(rows + cols - 1)
anti_diag_elements = [];
for i = 1:rows
j = k - i + 1;
if j >= 1 && j <= cols
anti_diag_elements = [anti_diag_elements; reconstructed_trajectory(i, j)];
end
end
reconstructed_signal(k) = mean(anti_diag_elements);
counts(k) = length(anti_diag_elements);
end
reconstructed_signal = reconstructed_signal ./ counts; % Normalize the signal
reconstructed_signal = reconstructed_signal(1:original_length);
end
% Perform SSA
window_length = floor(length(signal) / 3); % Adjust window length
X = trajectory_matrix(signal, window_length);
% Perform SVD decomposition
[U, S_mat, V] = svd(X, 'econ');
S = diag(S_mat);
% Calculate Singular Entropy for each component cumulatively
cumulative_entropy = zeros(length(S), 1);
for i = 1:length(S)
cumulative_entropy(i) = singular_entropy(S(1:i));
end
% Plot Singular Entropy to observe stabilization point
figure;
plot(1:length(S), cumulative_entropy, '-o', 'LineWidth', 1.5);
xlabel('Component Index');
ylabel('Cumulative Singular Entropy');
title('Cumulative Singular Entropy vs. Component Index');
grid on;
% Calculate the point where entropy stabilizes
entropy_diff = diff(cumulative_entropy); % Difference between consecutive entropy values
threshold = 0.01; % Threshold to detect stabilization
stable_point = find(entropy_diff < threshold, 1);
% Mark the stabilization point
hold on;
xline(stable_point + 1, '--r', ['Stabilization Point: ', num2str(stable_point + 1)]);
legend('Cumulative Singular Entropy', 'Stabilization Point');
% Number of components based on entropy stabilization
num_components = stable_point + 1;
disp(['Number of components based on entropy stabilization: ', num2str(num_components)]);
% Reconstruct the signal by categorizing components
trend_indices = 1; % Trend corresponds to the first component
oscillation_indices = 2:num_components; % Oscillations from second component to stabilization point
noise_indices = (num_components + 1):length(S); % Noise corresponds to components after stabilization
% Reconstruct signals based on selected indices
trend_signal = reconstruct_signal(U, S, V', trend_indices, length(signal));
oscillation_signal = reconstruct_signal(U, S, V', oscillation_indices, length(signal));
noise_signal = reconstruct_signal(U, S, V', noise_indices, length(signal));
% Plot the original signal, Trend, Oscillations, and Noise
figure;
plot(signal, 'b', 'DisplayName', 'Original Signal', 'LineWidth', 1.5);
hold on;
plot(trend_signal, 'g', 'DisplayName', 'Trend', 'LineWidth', 1.5);
plot(oscillation_signal, 'orange', 'DisplayName', 'Oscillations', 'LineWidth', 1.5);
plot(noise_signal, 'r', 'DisplayName', 'Noise', 'LineWidth', 1.5);
title('Signal Decomposition');
xlabel('Time');
ylabel('Amplitude');
legend;
grid on;

Answers (1)

William Rose
William Rose on 14 Jan 2025
You say SSA decomposes a signal into three components: trend, oscillations, and noise. Shouldn't the sum of the three components equal the signal? Even if the point of entropy stabilization is not found correctly? In your second plot, the three components do not add up to the orignal signal. I would fix that before working on a better way to find the point of entropy stabilization.
When I run your code with your data, I get an error - see below.
I notice that reconstruct_signal is defined
function reconstructed_signal = reconstruct_signal(U, S, V, indices, original_length)
and that you pass V', not V, when you call it. But changing V' to V in the call did not fix the error. I would check vector and array dimensions in reconstruct_signal(). Then we'll get to the point of entropy stabilization.
More later.
% Load the CSV file
data = importdata('VAL320.csv');
signal=data.data;
signal = signal(~isnan(signal)); % Drop NaN values
% SSA Functions
function X = trajectory_matrix(signal, window_length)
N = length(signal);
K = N - window_length + 1;
X = zeros(window_length, K);
for i = 1:K
X(:, i) = signal(i:i + window_length - 1);
end
end
function entropy = singular_entropy(S)
P = S / sum(S);
entropy = -sum(P .* log(P));
end
function reconstructed_signal = reconstruct_signal(U, S, V, indices, original_length)
reconstructed_trajectory = zeros(size(U, 1), size(V, 1));
for i = indices
reconstructed_trajectory = reconstructed_trajectory + S(i) * (U(:, i) * V(i, :));
end
[rows, cols] = size(reconstructed_trajectory);
signal_length = rows + cols - 1;
reconstructed_signal = zeros(signal_length, 1);
counts = zeros(signal_length, 1);
% Extracting anti-diagonals
for k = 1:(rows + cols - 1)
anti_diag_elements = [];
for i = 1:rows
j = k - i + 1;
if j >= 1 && j <= cols
anti_diag_elements = [anti_diag_elements; reconstructed_trajectory(i, j)];
end
end
reconstructed_signal(k) = mean(anti_diag_elements);
counts(k) = length(anti_diag_elements);
end
reconstructed_signal = reconstructed_signal ./ counts; % Normalize the signal
reconstructed_signal = reconstructed_signal(1:original_length);
end
% Perform SSA
window_length = floor(length(signal) / 3); % Adjust window length
X = trajectory_matrix(signal, window_length);
% Perform SVD decomposition
[U, S_mat, V] = svd(X, 'econ');
S = diag(S_mat);
% Calculate Singular Entropy for each component cumulatively
cumulative_entropy = zeros(length(S), 1);
for i = 1:length(S)
cumulative_entropy(i) = singular_entropy(S(1:i));
end
% Plot Singular Entropy to observe stabilization point
figure;
plot(1:length(S), cumulative_entropy, '-o', 'LineWidth', 1.5);
xlabel('Component Index');
ylabel('Cumulative Singular Entropy');
title('Cumulative Singular Entropy vs. Component Index');
grid on;
% Calculate the point where entropy stabilizes
entropy_diff = diff(cumulative_entropy); % Difference between consecutive entropy values
threshold = 0.01; % Threshold to detect stabilization
stable_point = find(entropy_diff < threshold, 1);
% Mark the stabilization point
hold on;
xline(stable_point + 1, '--r', ['Stabilization Point: ', num2str(stable_point + 1)]);
legend('Cumulative Singular Entropy', 'Stabilization Point');
% Number of components based on entropy stabilization
num_components = stable_point + 1;
disp(['Number of components based on entropy stabilization: ', num2str(num_components)]);
Number of components based on entropy stabilization: 64
% Reconstruct the signal by categorizing components
trend_indices = 1; % Trend corresponds to the first component
oscillation_indices = 2:num_components; % Oscillations from second component to stabilization point
noise_indices = (num_components + 1):length(S); % Noise corresponds to components after stabilization
% Reconstruct signals based on selected indices
trend_signal = reconstruct_signal(U, S, V', trend_indices, length(signal));
Arrays have incompatible sizes for this operation.

Error in solution>reconstruct_signal (line 22)
reconstructed_trajectory = reconstructed_trajectory + S(i) * (U(:, i) * V(i, :));
oscillation_signal = reconstruct_signal(U, S, V', oscillation_indices, length(signal));
noise_signal = reconstruct_signal(U, S, V', noise_indices, length(signal));
% Plot the original signal, Trend, Oscillations, and Noise
figure;
plot(signal, 'b', 'DisplayName', 'Original Signal', 'LineWidth', 1.5);
hold on;
plot(trend_signal, 'g', 'DisplayName', 'Trend', 'LineWidth', 1.5);
plot(oscillation_signal, 'orange', 'DisplayName', 'Oscillations', 'LineWidth', 1.5);
plot(noise_signal, 'r', 'DisplayName', 'Noise', 'LineWidth', 1.5);
title('Signal Decomposition');
xlabel('Time');
ylabel('Amplitude');
legend;
grid on;
OK
  9 Comments
William Rose
William Rose on 20 Jan 2025
Do you have a reference explaining the use and justification for the entropy stabilization point in SSA? I am asking because the book Singular Spectrum Analysis for Time Series, 2nd edition (2020) by Golyandina and Zhigljavsky, does not mention the entropy stabilization point. This book, or its first edition, is a commonly cited authority for SSA. The authors do mentin other methods, whcih I was also thinking about before I got the book: use Akaike information criterion, or Bayes information criterion (AIC or BIC), to decide where to draw the line for noise. I used AIC to select the number of model components in this publication.
One could also take a graphical approach to decide which components are oscillation and which are noise. See image below, which uses real experimental data.
Source: William Rose. Biomedical Signal Processing Lecture Notes, 2024. Concept from D. Winter, Biomechanics, 3rd edition, 2004.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!