Tag Archives: matlab
how can i open .out extension file in matlab?
how can i open .out extension file in matlab ?how can i open .out extension file in matlab ? how can i open .out extension file in matlab ? .out, extension, file MATLAB Answers — New Questions
How to set axis of scatter3?
Hi,
I have a for loop that basically continuously plots points using drawnow corresponding to particles in an explosion. So far, I’ve got the 3D scatter plot to continuously graph the explosion, its just that the axis continually readjusts every couple iterations, and the point motion is distorted because of it. Is there any way to set the axis of scatter3D? I’ve checked online everywhere and couldn’t find an answer. Axis() doesn’t seem to do anything.
ThanksHi,
I have a for loop that basically continuously plots points using drawnow corresponding to particles in an explosion. So far, I’ve got the 3D scatter plot to continuously graph the explosion, its just that the axis continually readjusts every couple iterations, and the point motion is distorted because of it. Is there any way to set the axis of scatter3D? I’ve checked online everywhere and couldn’t find an answer. Axis() doesn’t seem to do anything.
Thanks Hi,
I have a for loop that basically continuously plots points using drawnow corresponding to particles in an explosion. So far, I’ve got the 3D scatter plot to continuously graph the explosion, its just that the axis continually readjusts every couple iterations, and the point motion is distorted because of it. Is there any way to set the axis of scatter3D? I’ve checked online everywhere and couldn’t find an answer. Axis() doesn’t seem to do anything.
Thanks scatter3, 3d plots, plot, data, axis MATLAB Answers — New Questions
Obtaining the P values for the t stat
I have both the tstat and the degrees of freedom, is there a quick way to find the P value of a two tailed hypothesis at a significance of 0.05I have both the tstat and the degrees of freedom, is there a quick way to find the P value of a two tailed hypothesis at a significance of 0.05 I have both the tstat and the degrees of freedom, is there a quick way to find the P value of a two tailed hypothesis at a significance of 0.05 matlab MATLAB Answers — New Questions
tlc_c (InvokeTLC) error when building Matlab R13
Getting the following error when trying to build model. Note: I have not had any environment changes nor changed the tlc files since last successful build:
"Error executing build command: Error using ==> make_rtw
Error using ==> tlc_c
Error using ==> tlc_c (InvokeTLC)
Error: File: C:MATLAB6p5p2rtwctlclibcachelib.tlc Line: 391 Column: 37
Undefined identifier buffer"Getting the following error when trying to build model. Note: I have not had any environment changes nor changed the tlc files since last successful build:
"Error executing build command: Error using ==> make_rtw
Error using ==> tlc_c
Error using ==> tlc_c (InvokeTLC)
Error: File: C:MATLAB6p5p2rtwctlclibcachelib.tlc Line: 391 Column: 37
Undefined identifier buffer" Getting the following error when trying to build model. Note: I have not had any environment changes nor changed the tlc files since last successful build:
"Error executing build command: Error using ==> make_rtw
Error using ==> tlc_c
Error using ==> tlc_c (InvokeTLC)
Error: File: C:MATLAB6p5p2rtwctlclibcachelib.tlc Line: 391 Column: 37
Undefined identifier buffer" real time workshop, error, tlc_c MATLAB Answers — New Questions
Can’t publish GitHub Release to File Exchange after changing GitHub username
After changing my GitHub username (From Silver-Fang to Ebola-Chan-bot, as shown in the screenshot), I can’t publish my GitHub releases any more. It just says that something went wrong and I don’t know what’s wrong.
I should have correctly set the integration App on GitHub side:After changing my GitHub username (From Silver-Fang to Ebola-Chan-bot, as shown in the screenshot), I can’t publish my GitHub releases any more. It just says that something went wrong and I don’t know what’s wrong.
I should have correctly set the integration App on GitHub side: After changing my GitHub username (From Silver-Fang to Ebola-Chan-bot, as shown in the screenshot), I can’t publish my GitHub releases any more. It just says that something went wrong and I don’t know what’s wrong.
I should have correctly set the integration App on GitHub side: file exchange, github MATLAB Answers — New Questions
Unexpected phases in fresnel diffraction using fft2
Hello everyone,
I’m relative new to Matlab and encountered trouble trying to realize a Fresnel-diffraction using the Fast-Fourier Algorithm.
Please apologize my somehow lacking English skills. Since it’s not my mother tongue, some of my explanations may sound a little bit weird.
I want to propagate a N x N matrix, whereas N is a power of 2.
The matrix I use as a test case describes a square which is symmetric to the middel of the matrix, I generate the matrix with the following code snippet:
A = zeros(256,256);
A(119:138, 119:138) = 100;
fresnelpropagation(A, 100, 0.682, 0.39, 0.39); %function call
I get a small 20px x 20px square in the middel of a 256 x 256 matrix.
The function I call looks like this:
function Aout=fresnelpropagation2( Ain ,z , lambda, dx , dy )
[nx, ny] = size(Ain);
k = 2*pi / lambda;
%dx and dy in distance z
dx2 = z*lambda/(nx * dx);
dy2 = z*lambda/(ny * dy);
%"coordinates" of matrix Ain
x1 = (-nx/2*dx2 + dx2/2 : dx2 : nx/2*dx2 – dx2/2);
y1 = (-ny/2*dy2 + dy2/2 : dy2 : ny/2*dy2 – dy2/2);
[X1, Y1] = meshgrid(x1 *dx,y1 *dy);
%Phase of matrix Ain and FFT of Ain
AFtPart = Ain.*exp(1i*k*z + (1i*k/(2*z)).*(X1.^2 + Y1.^2));
AFt = fftshift(fft2(ifftshift(AFtPart)));
%"coordinates" of matrix Aout
x2 = (-nx/2*dx2 + dx2/2 : dx2 : nx/2*dx2 – dx2/2);
y2 = (-ny/2*dy2 + dy2/2 : dy2 : ny/2*dy2 – dy2/2);
[X2, Y2] = meshgrid(x2, y2);
%compare Sf(x,y) in formula
AFoldCore = (1i*k /(2*pi*z)).*exp((1i*k/(2*z)).*(X2.^2 + Y2.^2));
Aout = AFoldCore.*AFt;
end
The formula this algorithm is based on:
<</matlabcentral/answers/uploaded_files/63558/help.PNG>>
_Image 1: Formula for diffraction_
My result for the amplitude of Aout is as expected, the problem lies within the phases, they are not symmetrical (obvious asymmetrical part marked in the picture):
<</matlabcentral/answers/uploaded_files/63559/help2.PNG>>
_Image 2: Amplitude and Phase of Aout_
So I tried to find out where this asymetrical part came into existence. AFoldCore proved to be symmetric, AFtPart appears to be symmetric as well, but the phases of AFt itself are not symmetric:
<</matlabcentral/answers/uploaded_files/63561/help3.PNG>>
_Image 3: Amplitude and Phase of AFt_
It appears as if a Sine with a rather low frequency was mulitplied into the phase. It ´"starts"
in the top left corner and goes down to the bottom right corner.
After some try and error I decided to use the same algorithm for a Matrix with an odd size:
>> A = zeros(257,257);
>> A(119:139, 119:139) = 100;
>> fresnelpropagation(A, 100, 0.682, 0.39, 0.39);
The phase of Aout is symmetric, furthermore the phase of AFt is symmetric as well.
Because I need to use the algorithm a lot of times in my program I intend to work with matrixes,
with a size of N x N, whereas N is a power of 2 for perfomance reasons. Due to that simply "upsacling" to N+1 x N+1 is not a possible solution.
I think I know where the error is to be found: The ifftshift is not able to flip along a Pixel with the coordinates [0,0] if N is even. Due to that somehow the sine enters the phase.
My question is how am I able to surpress this sine in my phase without upscaling my Matrix?
Or is there something wrong with my code?
Thank you for your time and attention.
Best regards,
AdrianHello everyone,
I’m relative new to Matlab and encountered trouble trying to realize a Fresnel-diffraction using the Fast-Fourier Algorithm.
Please apologize my somehow lacking English skills. Since it’s not my mother tongue, some of my explanations may sound a little bit weird.
I want to propagate a N x N matrix, whereas N is a power of 2.
The matrix I use as a test case describes a square which is symmetric to the middel of the matrix, I generate the matrix with the following code snippet:
A = zeros(256,256);
A(119:138, 119:138) = 100;
fresnelpropagation(A, 100, 0.682, 0.39, 0.39); %function call
I get a small 20px x 20px square in the middel of a 256 x 256 matrix.
The function I call looks like this:
function Aout=fresnelpropagation2( Ain ,z , lambda, dx , dy )
[nx, ny] = size(Ain);
k = 2*pi / lambda;
%dx and dy in distance z
dx2 = z*lambda/(nx * dx);
dy2 = z*lambda/(ny * dy);
%"coordinates" of matrix Ain
x1 = (-nx/2*dx2 + dx2/2 : dx2 : nx/2*dx2 – dx2/2);
y1 = (-ny/2*dy2 + dy2/2 : dy2 : ny/2*dy2 – dy2/2);
[X1, Y1] = meshgrid(x1 *dx,y1 *dy);
%Phase of matrix Ain and FFT of Ain
AFtPart = Ain.*exp(1i*k*z + (1i*k/(2*z)).*(X1.^2 + Y1.^2));
AFt = fftshift(fft2(ifftshift(AFtPart)));
%"coordinates" of matrix Aout
x2 = (-nx/2*dx2 + dx2/2 : dx2 : nx/2*dx2 – dx2/2);
y2 = (-ny/2*dy2 + dy2/2 : dy2 : ny/2*dy2 – dy2/2);
[X2, Y2] = meshgrid(x2, y2);
%compare Sf(x,y) in formula
AFoldCore = (1i*k /(2*pi*z)).*exp((1i*k/(2*z)).*(X2.^2 + Y2.^2));
Aout = AFoldCore.*AFt;
end
The formula this algorithm is based on:
<</matlabcentral/answers/uploaded_files/63558/help.PNG>>
_Image 1: Formula for diffraction_
My result for the amplitude of Aout is as expected, the problem lies within the phases, they are not symmetrical (obvious asymmetrical part marked in the picture):
<</matlabcentral/answers/uploaded_files/63559/help2.PNG>>
_Image 2: Amplitude and Phase of Aout_
So I tried to find out where this asymetrical part came into existence. AFoldCore proved to be symmetric, AFtPart appears to be symmetric as well, but the phases of AFt itself are not symmetric:
<</matlabcentral/answers/uploaded_files/63561/help3.PNG>>
_Image 3: Amplitude and Phase of AFt_
It appears as if a Sine with a rather low frequency was mulitplied into the phase. It ´"starts"
in the top left corner and goes down to the bottom right corner.
After some try and error I decided to use the same algorithm for a Matrix with an odd size:
>> A = zeros(257,257);
>> A(119:139, 119:139) = 100;
>> fresnelpropagation(A, 100, 0.682, 0.39, 0.39);
The phase of Aout is symmetric, furthermore the phase of AFt is symmetric as well.
Because I need to use the algorithm a lot of times in my program I intend to work with matrixes,
with a size of N x N, whereas N is a power of 2 for perfomance reasons. Due to that simply "upsacling" to N+1 x N+1 is not a possible solution.
I think I know where the error is to be found: The ifftshift is not able to flip along a Pixel with the coordinates [0,0] if N is even. Due to that somehow the sine enters the phase.
My question is how am I able to surpress this sine in my phase without upscaling my Matrix?
Or is there something wrong with my code?
Thank you for your time and attention.
Best regards,
Adrian Hello everyone,
I’m relative new to Matlab and encountered trouble trying to realize a Fresnel-diffraction using the Fast-Fourier Algorithm.
Please apologize my somehow lacking English skills. Since it’s not my mother tongue, some of my explanations may sound a little bit weird.
I want to propagate a N x N matrix, whereas N is a power of 2.
The matrix I use as a test case describes a square which is symmetric to the middel of the matrix, I generate the matrix with the following code snippet:
A = zeros(256,256);
A(119:138, 119:138) = 100;
fresnelpropagation(A, 100, 0.682, 0.39, 0.39); %function call
I get a small 20px x 20px square in the middel of a 256 x 256 matrix.
The function I call looks like this:
function Aout=fresnelpropagation2( Ain ,z , lambda, dx , dy )
[nx, ny] = size(Ain);
k = 2*pi / lambda;
%dx and dy in distance z
dx2 = z*lambda/(nx * dx);
dy2 = z*lambda/(ny * dy);
%"coordinates" of matrix Ain
x1 = (-nx/2*dx2 + dx2/2 : dx2 : nx/2*dx2 – dx2/2);
y1 = (-ny/2*dy2 + dy2/2 : dy2 : ny/2*dy2 – dy2/2);
[X1, Y1] = meshgrid(x1 *dx,y1 *dy);
%Phase of matrix Ain and FFT of Ain
AFtPart = Ain.*exp(1i*k*z + (1i*k/(2*z)).*(X1.^2 + Y1.^2));
AFt = fftshift(fft2(ifftshift(AFtPart)));
%"coordinates" of matrix Aout
x2 = (-nx/2*dx2 + dx2/2 : dx2 : nx/2*dx2 – dx2/2);
y2 = (-ny/2*dy2 + dy2/2 : dy2 : ny/2*dy2 – dy2/2);
[X2, Y2] = meshgrid(x2, y2);
%compare Sf(x,y) in formula
AFoldCore = (1i*k /(2*pi*z)).*exp((1i*k/(2*z)).*(X2.^2 + Y2.^2));
Aout = AFoldCore.*AFt;
end
The formula this algorithm is based on:
<</matlabcentral/answers/uploaded_files/63558/help.PNG>>
_Image 1: Formula for diffraction_
My result for the amplitude of Aout is as expected, the problem lies within the phases, they are not symmetrical (obvious asymmetrical part marked in the picture):
<</matlabcentral/answers/uploaded_files/63559/help2.PNG>>
_Image 2: Amplitude and Phase of Aout_
So I tried to find out where this asymetrical part came into existence. AFoldCore proved to be symmetric, AFtPart appears to be symmetric as well, but the phases of AFt itself are not symmetric:
<</matlabcentral/answers/uploaded_files/63561/help3.PNG>>
_Image 3: Amplitude and Phase of AFt_
It appears as if a Sine with a rather low frequency was mulitplied into the phase. It ´"starts"
in the top left corner and goes down to the bottom right corner.
After some try and error I decided to use the same algorithm for a Matrix with an odd size:
>> A = zeros(257,257);
>> A(119:139, 119:139) = 100;
>> fresnelpropagation(A, 100, 0.682, 0.39, 0.39);
The phase of Aout is symmetric, furthermore the phase of AFt is symmetric as well.
Because I need to use the algorithm a lot of times in my program I intend to work with matrixes,
with a size of N x N, whereas N is a power of 2 for perfomance reasons. Due to that simply "upsacling" to N+1 x N+1 is not a possible solution.
I think I know where the error is to be found: The ifftshift is not able to flip along a Pixel with the coordinates [0,0] if N is even. Due to that somehow the sine enters the phase.
My question is how am I able to surpress this sine in my phase without upscaling my Matrix?
Or is there something wrong with my code?
Thank you for your time and attention.
Best regards,
Adrian fft2, phases error, fft, fresnel diffraction MATLAB Answers — New Questions
Problem with identifying the entropy stabilization point in SSA for accurate signal decomposition.
In Singular Spectrum Analysis (SSA), the goal is to decompose a signal into three main components:
Trend: The overall trend of the signal, which represents long-term changes.
Oscillations: Parts of the signal that change periodically, typically corresponding to medium-term variations.
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;In Singular Spectrum Analysis (SSA), the goal is to decompose a signal into three main components:
Trend: The overall trend of the signal, which represents long-term changes.
Oscillations: Parts of the signal that change periodically, typically corresponding to medium-term variations.
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; In Singular Spectrum Analysis (SSA), the goal is to decompose a signal into three main components:
Trend: The overall trend of the signal, which represents long-term changes.
Oscillations: Parts of the signal that change periodically, typically corresponding to medium-term variations.
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; singular spectrum analysis, ssa, entropy, signal d MATLAB Answers — New Questions
Can a Simulink model inherit Data Dictionary links from libraries blocks within other libraries or subsystem references?
I’m working in R2022b. I can build a library, associate a data dictionary with it, then when I use a block from the library in a model the data dictionary shows up in the Model Explorer under External Data > From Libraries. Which is awesome, because I want to associate the component-specific data with their respective libraries then never have to relink those data dictionaries as I use the library blocks throughout my model.
My issue is that as soon as I’m using a library block in a subsystem reference or another library the top-level model won’t find the data dictionary. It only finds library linked data dictionaries within the top model file. Can I make it pull in library linked data dictionaries wherever it finds them in the tree?I’m working in R2022b. I can build a library, associate a data dictionary with it, then when I use a block from the library in a model the data dictionary shows up in the Model Explorer under External Data > From Libraries. Which is awesome, because I want to associate the component-specific data with their respective libraries then never have to relink those data dictionaries as I use the library blocks throughout my model.
My issue is that as soon as I’m using a library block in a subsystem reference or another library the top-level model won’t find the data dictionary. It only finds library linked data dictionaries within the top model file. Can I make it pull in library linked data dictionaries wherever it finds them in the tree? I’m working in R2022b. I can build a library, associate a data dictionary with it, then when I use a block from the library in a model the data dictionary shows up in the Model Explorer under External Data > From Libraries. Which is awesome, because I want to associate the component-specific data with their respective libraries then never have to relink those data dictionaries as I use the library blocks throughout my model.
My issue is that as soon as I’m using a library block in a subsystem reference or another library the top-level model won’t find the data dictionary. It only finds library linked data dictionaries within the top model file. Can I make it pull in library linked data dictionaries wherever it finds them in the tree? subsystem references, data dictionaries MATLAB Answers — New Questions
Thingspeak – TCP disconnection after channel update
Hello,
When updating the channel feed the TCP connection is terminated by the Thingspeak server immediately after each request (doesn’t matter "bad" or "good").
That behavior does not depend on the method I use (reqests from ESP8266 via WiFi, GPRS, ordinary terminal program under Windows etc.)
Is that normal?
From technical point of view this is not a problem but when using GPRS the service provider charges me for 100kB of data each time the new TCP connection is open (even if seding 100 bytes) so I suspect it would be better (cheaper) to keep the connection open between the reqests.
Thank you in advance for any advice.Hello,
When updating the channel feed the TCP connection is terminated by the Thingspeak server immediately after each request (doesn’t matter "bad" or "good").
That behavior does not depend on the method I use (reqests from ESP8266 via WiFi, GPRS, ordinary terminal program under Windows etc.)
Is that normal?
From technical point of view this is not a problem but when using GPRS the service provider charges me for 100kB of data each time the new TCP connection is open (even if seding 100 bytes) so I suspect it would be better (cheaper) to keep the connection open between the reqests.
Thank you in advance for any advice. Hello,
When updating the channel feed the TCP connection is terminated by the Thingspeak server immediately after each request (doesn’t matter "bad" or "good").
That behavior does not depend on the method I use (reqests from ESP8266 via WiFi, GPRS, ordinary terminal program under Windows etc.)
Is that normal?
From technical point of view this is not a problem but when using GPRS the service provider charges me for 100kB of data each time the new TCP connection is open (even if seding 100 bytes) so I suspect it would be better (cheaper) to keep the connection open between the reqests.
Thank you in advance for any advice. tcp, disconnection MATLAB Answers — New Questions
Function ‘contains’ did not work
The background is CODY problem 95
The purpose is to confirm whether the vector s1 contains the vector s2. (or s2 cover s1)
The problem is that when the size of the vector is very large, the function ’contains‘ cannot be judged correctly.
case 1
clear
s1 = 1:100;
s2 = [50 51];
s1str=num2str(s1);
s2str=num2str(s2);
tf1=contains(s1str,s2str)
tf2=contains(s2str,s1str)
tf1 SHOULD be 1, since [50 51] is part of s1. but the result is not correct.
case 2
s1 = 40:60;
s2 = [50 51];
s1str=num2str(s1);
s2str=num2str(s2);
tf1=contains(s1str,s2str)
tf2=contains(s2str,s1str)
When the size of the vector S1 decreases, the function works normally.The background is CODY problem 95
The purpose is to confirm whether the vector s1 contains the vector s2. (or s2 cover s1)
The problem is that when the size of the vector is very large, the function ’contains‘ cannot be judged correctly.
case 1
clear
s1 = 1:100;
s2 = [50 51];
s1str=num2str(s1);
s2str=num2str(s2);
tf1=contains(s1str,s2str)
tf2=contains(s2str,s1str)
tf1 SHOULD be 1, since [50 51] is part of s1. but the result is not correct.
case 2
s1 = 40:60;
s2 = [50 51];
s1str=num2str(s1);
s2str=num2str(s2);
tf1=contains(s1str,s2str)
tf2=contains(s2str,s1str)
When the size of the vector S1 decreases, the function works normally. The background is CODY problem 95
The purpose is to confirm whether the vector s1 contains the vector s2. (or s2 cover s1)
The problem is that when the size of the vector is very large, the function ’contains‘ cannot be judged correctly.
case 1
clear
s1 = 1:100;
s2 = [50 51];
s1str=num2str(s1);
s2str=num2str(s2);
tf1=contains(s1str,s2str)
tf2=contains(s2str,s1str)
tf1 SHOULD be 1, since [50 51] is part of s1. but the result is not correct.
case 2
s1 = 40:60;
s2 = [50 51];
s1str=num2str(s1);
s2str=num2str(s2);
tf1=contains(s1str,s2str)
tf2=contains(s2str,s1str)
When the size of the vector S1 decreases, the function works normally. function, contains MATLAB Answers — New Questions
Error Installing Autosar package in 2015b matlab
I just installed a trial version of matlab 2015b and I need to add the Autosar package. I just download it and now trying to install it but I get this error from the Support package installer "Unable to load support package information. This may be duw to network problemas. Verify your network connection and retry the support package installation. If the problem persist, contact MathWorks technical support"
I check my network and I have good connection and speed. I alredy did around 20 retries but the issue persist. I noticed that other users experiences the same issue, one of them said retrying fix the problem, but that is not working for me.I just installed a trial version of matlab 2015b and I need to add the Autosar package. I just download it and now trying to install it but I get this error from the Support package installer "Unable to load support package information. This may be duw to network problemas. Verify your network connection and retry the support package installation. If the problem persist, contact MathWorks technical support"
I check my network and I have good connection and speed. I alredy did around 20 retries but the issue persist. I noticed that other users experiences the same issue, one of them said retrying fix the problem, but that is not working for me. I just installed a trial version of matlab 2015b and I need to add the Autosar package. I just download it and now trying to install it but I get this error from the Support package installer "Unable to load support package information. This may be duw to network problemas. Verify your network connection and retry the support package installation. If the problem persist, contact MathWorks technical support"
I check my network and I have good connection and speed. I alredy did around 20 retries but the issue persist. I noticed that other users experiences the same issue, one of them said retrying fix the problem, but that is not working for me. autosar, package installation MATLAB Answers — New Questions
Not getting full range of servo when running from Simulink
Hello, I have a very simple Simulink program to control a servo with my Arduino. The problem is that I’m not getting a full range of the servo. I am using an Adafruit Motor Shield to drive the servo which is a cheap TowerPro. The range I’m getting is 0 to 70. I am using Matlab/Simulink 2019.
Any ideas what could be wrong?
Thank youHello, I have a very simple Simulink program to control a servo with my Arduino. The problem is that I’m not getting a full range of the servo. I am using an Adafruit Motor Shield to drive the servo which is a cheap TowerPro. The range I’m getting is 0 to 70. I am using Matlab/Simulink 2019.
Any ideas what could be wrong?
Thank you Hello, I have a very simple Simulink program to control a servo with my Arduino. The problem is that I’m not getting a full range of the servo. I am using an Adafruit Motor Shield to drive the servo which is a cheap TowerPro. The range I’m getting is 0 to 70. I am using Matlab/Simulink 2019.
Any ideas what could be wrong?
Thank you simulink, arduino, full range, servo, adafruit MATLAB Answers — New Questions
How to get the value from a inport of a customed block with s-function and tlc concept
Hello all,
Currently I have a Simulink customed block (named as Teq block) for my own project which was built in s-function for simulation and tlc for code generation. Because of some reasons on algorithm, I have to find a way to get the value of a Simulink.Parameter(another block) via my Teq_sf.tlc file. However, my tlc file can only get the name of Simulink.Parameter instead of its value as my expectation.
I tried to define a mdlRTW function in sf.c file and call this input to tlc file via RTW, as followings:
static void mdlRTW(SimStruct *S) % in sf.c file
{
real64 *u1 = (real64 *) ssGetInputPortSignal(S, 0);
if (!ssWriteRTWParamSettings( S, 1, SSWRITE_VALUE_QSTR, "Input_Value", *u1))
{
ssSetErrorStatus(S,"Error writing parameter data to .rtw file");
return;
}
}
and %assign input_value = SFcnParamSettings.Input_Value (in tlc)
However, this way did not work because system can not understand SFcnParamSettings. Currently, this is the big blocker for my progress.
Do you know any valid solutions which I can get a value of Simulink.Parameter into my Teq_sf.tlc file but not the name?
Thank you in advance!Hello all,
Currently I have a Simulink customed block (named as Teq block) for my own project which was built in s-function for simulation and tlc for code generation. Because of some reasons on algorithm, I have to find a way to get the value of a Simulink.Parameter(another block) via my Teq_sf.tlc file. However, my tlc file can only get the name of Simulink.Parameter instead of its value as my expectation.
I tried to define a mdlRTW function in sf.c file and call this input to tlc file via RTW, as followings:
static void mdlRTW(SimStruct *S) % in sf.c file
{
real64 *u1 = (real64 *) ssGetInputPortSignal(S, 0);
if (!ssWriteRTWParamSettings( S, 1, SSWRITE_VALUE_QSTR, "Input_Value", *u1))
{
ssSetErrorStatus(S,"Error writing parameter data to .rtw file");
return;
}
}
and %assign input_value = SFcnParamSettings.Input_Value (in tlc)
However, this way did not work because system can not understand SFcnParamSettings. Currently, this is the big blocker for my progress.
Do you know any valid solutions which I can get a value of Simulink.Parameter into my Teq_sf.tlc file but not the name?
Thank you in advance! Hello all,
Currently I have a Simulink customed block (named as Teq block) for my own project which was built in s-function for simulation and tlc for code generation. Because of some reasons on algorithm, I have to find a way to get the value of a Simulink.Parameter(another block) via my Teq_sf.tlc file. However, my tlc file can only get the name of Simulink.Parameter instead of its value as my expectation.
I tried to define a mdlRTW function in sf.c file and call this input to tlc file via RTW, as followings:
static void mdlRTW(SimStruct *S) % in sf.c file
{
real64 *u1 = (real64 *) ssGetInputPortSignal(S, 0);
if (!ssWriteRTWParamSettings( S, 1, SSWRITE_VALUE_QSTR, "Input_Value", *u1))
{
ssSetErrorStatus(S,"Error writing parameter data to .rtw file");
return;
}
}
and %assign input_value = SFcnParamSettings.Input_Value (in tlc)
However, this way did not work because system can not understand SFcnParamSettings. Currently, this is the big blocker for my progress.
Do you know any valid solutions which I can get a value of Simulink.Parameter into my Teq_sf.tlc file but not the name?
Thank you in advance! matlab, simulink, s-function, tlc MATLAB Answers — New Questions
how to extract features from 350 clusters | extractEigenFeatures
Hello All,
I have around 350 clusters and I am trying to retain only matching clusters and remove unmatched ones. How to use this example in this case https://www.mathworks.com/help/lidar/ref/pcshowmatchedfeatures.htmlHello All,
I have around 350 clusters and I am trying to retain only matching clusters and remove unmatched ones. How to use this example in this case https://www.mathworks.com/help/lidar/ref/pcshowmatchedfeatures.html Hello All,
I have around 350 clusters and I am trying to retain only matching clusters and remove unmatched ones. How to use this example in this case https://www.mathworks.com/help/lidar/ref/pcshowmatchedfeatures.html lidar, cluster, eigen, featueres MATLAB Answers — New Questions
how to convert pcap to ply
Hello All,
I have velodyne lidar data in .pcap format. How to convert .pcap data into ply file?Hello All,
I have velodyne lidar data in .pcap format. How to convert .pcap data into ply file? Hello All,
I have velodyne lidar data in .pcap format. How to convert .pcap data into ply file? 3d, lidar, pointcloud, 3dobject, lidar_data MATLAB Answers — New Questions
Where is the MATLAB Connector installation log file located?
Where can I find the installation log files for the MATLAB Connector so that I may troubleshoot potential installation issues?Where can I find the installation log files for the MATLAB Connector so that I may troubleshoot potential installation issues? Where can I find the installation log files for the MATLAB Connector so that I may troubleshoot potential installation issues? MATLAB Answers — New Questions
How to Incorporate Explanatory Variables in State Equations Using the bnlssm Package?
Hello everyone,
I’m currently working with the bnlssm package in MATLAB to model a nonlinear state-space system. My goal is to include explanatory variables in the state equation, but I’m encountering some challenges and need your help.
Specifically, I want to modify the state equation to include external explanatory variables , such as:
In this setup:
• is the state variable.
• is an explanatory variable (could be a vector or scalar).
• represents the influence of the explanatory variable on the state dynamics.
My Questions:
1. Does the bnlssm package support incorporating explanatory variables directly into the state equation?
2. If it does, are there any specific examples or documentation that demonstrate how to achieve this?
3. If not, is there a recommended workaround for including explanatory variables, such as extending the state vector or using another approach?Hello everyone,
I’m currently working with the bnlssm package in MATLAB to model a nonlinear state-space system. My goal is to include explanatory variables in the state equation, but I’m encountering some challenges and need your help.
Specifically, I want to modify the state equation to include external explanatory variables , such as:
In this setup:
• is the state variable.
• is an explanatory variable (could be a vector or scalar).
• represents the influence of the explanatory variable on the state dynamics.
My Questions:
1. Does the bnlssm package support incorporating explanatory variables directly into the state equation?
2. If it does, are there any specific examples or documentation that demonstrate how to achieve this?
3. If not, is there a recommended workaround for including explanatory variables, such as extending the state vector or using another approach? Hello everyone,
I’m currently working with the bnlssm package in MATLAB to model a nonlinear state-space system. My goal is to include explanatory variables in the state equation, but I’m encountering some challenges and need your help.
Specifically, I want to modify the state equation to include external explanatory variables , such as:
In this setup:
• is the state variable.
• is an explanatory variable (could be a vector or scalar).
• represents the influence of the explanatory variable on the state dynamics.
My Questions:
1. Does the bnlssm package support incorporating explanatory variables directly into the state equation?
2. If it does, are there any specific examples or documentation that demonstrate how to achieve this?
3. If not, is there a recommended workaround for including explanatory variables, such as extending the state vector or using another approach? state space model, state equation, bnlssm package MATLAB Answers — New Questions
SNR Calculation on the basis of channel estimation using Pilot Symbols
Hi,
I wanted to ask how can we calculate SNR on the basis of channel estimation using Pilot Symbols and make CQI table for Adaptive modulation coding according to the estiamted SNR values.
RegardsHi,
I wanted to ask how can we calculate SNR on the basis of channel estimation using Pilot Symbols and make CQI table for Adaptive modulation coding according to the estiamted SNR values.
Regards Hi,
I wanted to ask how can we calculate SNR on the basis of channel estimation using Pilot Symbols and make CQI table for Adaptive modulation coding according to the estiamted SNR values.
Regards channel estimation, snr, modulation, adaptive modulation, amc MATLAB Answers — New Questions
UAV simulation in lunar environment
Hello Everyone
My question is it is possible to simulate and perform communication between multiple UAV in lunar environment using MATLAB and SIMULINK. If yes, which toolbox we need to use.
Thank you in advance.Hello Everyone
My question is it is possible to simulate and perform communication between multiple UAV in lunar environment using MATLAB and SIMULINK. If yes, which toolbox we need to use.
Thank you in advance. Hello Everyone
My question is it is possible to simulate and perform communication between multiple UAV in lunar environment using MATLAB and SIMULINK. If yes, which toolbox we need to use.
Thank you in advance. uav, lunar, simulink MATLAB Answers — New Questions
Deconvolution of two different Gaussians
Hi all
I’m convolving two different Gaussians: straggling and espread. But when I deconvolve the resultant I see either straggling or "nonsense". Is it possible to deconvolve the resultant in such a way that I see espread? My code is attached.
Sorry, bit of a noob question.
Regards
TimHi all
I’m convolving two different Gaussians: straggling and espread. But when I deconvolve the resultant I see either straggling or "nonsense". Is it possible to deconvolve the resultant in such a way that I see espread? My code is attached.
Sorry, bit of a noob question.
Regards
Tim Hi all
I’m convolving two different Gaussians: straggling and espread. But when I deconvolve the resultant I see either straggling or "nonsense". Is it possible to deconvolve the resultant in such a way that I see espread? My code is attached.
Sorry, bit of a noob question.
Regards
Tim convolution MATLAB Answers — New Questions