Borrar filtros
Borrar filtros

original script uses random number generation as its input - to fit my needs requires input of lab data I have collected instead of random number; I get 1-by-0 errors

1 visualización (últimos 30 días)
% DFM Allan Deviation
% 3-16-22
% Provides Allan Deviation Curve for inputted Data file in .TXT format
% .TXT file sample time is manually inputted as SpS
clc
SpS = 25; % samples per Second
Fs = double(SpS);
% count the number of lines in the text file then deposit in LC
lines = -inf;[fid,msg] = fopen('11.txt', 'r');
linecount = 0;
lines_in_file = 0;
while ~feof(fid)
thisline = fgetl(fid);
if ~ischar(thisline); break; end
linecount = linecount +1;
num_nonspace = nnz(~isspace(thisline));
if num_nonspace >0
lines_in_file = linecount;
end
end
disp(linecount);
LC = linecount-1;
omega = double(LC);
%omega = LC
load ('11'); % input the data
t0x = 1/SpS; % determine tau from samples per second, SpS (entered at top)
t0 = double(t0x);
thetax = cumsum(omega, 1)*t0;
theta = double(thetax);
%display(theta);
%display(t0);
%display(omega);
maxNumM = 1000000;
L = size(theta, 1);
display(theta);
maxM = 2.^floor(log2(L/2));
m = logspace(log10(1), log10(maxM), maxNumM).';
m = ceil(m); % must be Integer Value
m = unique(m); % remove duplicates
display(L);
tau = m*t0;
%disp(m);
avar = NaN(numel(m), 1); % create a matrix of zeros to speed up memory access
for i = 1:numel(m)
mi = m(i);
avar(i,:) = sum((theta(1+2*mi:L) - 2*theta(1+mi:L-mi) + theta(1:L-2*mi)).^2, 1);
end
avar = avar ./ (2*tau.^2 .* (L - 2*m));
%disp(avar);
adev = sqrt(avar);
figure()
%loglog(tau, adev)
title('Allan Deviation')
xlabel('\tau');
ylabel('\sigma(\tau)')
grid on
axis equal
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-0.
Error in DFM_Allan_Deviation (line 57)
avar(i,:) = sum((theta(1+2*mi:L) - 2*theta(1+mi:L-mi) + theta(1:L-2*mi)).^2, 1);
(Here is the original file found in the help examples)
% Inertial Sensor Noise Indication using Allan Deviation
% this is the Allan Deviation part
% This script came from the Mathworks Help Section; search "Inertial Noise"
% The following is this script unchanged from the Mathworks example
% Load logged data from one axis of a three-axis gyroscope. This recording
% was done over a six hour period with a 100 Hz sampling rate.
load('LoggedSingleAxisGyroscope', 'omega', 'Fs')
t0 = 1/Fs;
theta = cumsum(omega, 1)*t0;
maxNumM = 100;
L = size(theta, 1);
maxM = 2.^floor(log2(L/2));
m = logspace(log10(1), log10(maxM), maxNumM).';
m = ceil(m); % m must be an integer.
m = unique(m); % Remove duplicates.
tau = m*t0;
avar = zeros(numel(m), 1);
for i = 1:numel(m)
mi = m(i);
avar(i,:) = sum( ...
(theta(1+2*mi:L) - 2*theta(1+mi:L-mi) + theta(1:L-2*mi)).^2, 1);
end
avar = avar ./ (2*tau.^2 .* (L - 2*m));
adev = sqrt(avar); % Allan Deviation is the Square root of Allan Variance
figure % Plot The Output
loglog(tau, adev)
title('Allan Deviation')
xlabel('\tau');
ylabel('\sigma(\tau)')
grid on
axis equal
% this script will not run because "omega" is not supplied ????
% I am trying to produce omega from my data to plug into this script.
% all I get is the "1-by-1 leftside does not match 1-by-0 right side"
  4 comentarios
Duane Melvin
Duane Melvin el 18 de Mzo. de 2022
what could I do to theta to make it not scalar???? I copied the script below for your convienience
theta = cumsum(omega, 1)*t0;
maxNumM = 100;
L = size(theta, 1);
maxM = 2.^floor(log2(L/2));
m = logspace(log10(1), log10(maxM), maxNumM).';
m = ceil(m); % m must be an integer.
m = unique(m); % Remove duplicates.
tau = m*t0;
avar = zeros(numel(m), 1);
for i = 1:numel(m)
mi = m(i);
avar(i,:) = sum( ...
(theta(1+2*mi:L) - 2*theta(1+mi:L-mi) + theta(1:L-2*mi)).^2, 1);
end

Iniciar sesión para comentar.

Respuestas (1)

Voss
Voss el 18 de Mzo. de 2022
Editada: Voss el 18 de Mzo. de 2022
It seems likely that omega should not be a scalar, because theta = cumsum(omega,1)*t0 with scalar omega is the same as theta = omega*t0 (i.e., doing cumsum on a scalar just returns the original scalar).
Should omega be the contents of the file 11.txt? If so, then you don't need to read (fopen/fgetl) and also load the file; you can do one or the other.
(By the way, don't forget that every fopen() needs an fclose()!)
% DFM Allan Deviation
% 3-16-22
% Provides Allan Deviation Curve for inputted Data file in .TXT format
% .TXT file sample time is manually inputted as SpS
clc
SpS = 25; % samples per Second
Fs = double(SpS);
% count the number of lines in the text file then deposit in LC
% lines = -inf;[fid,msg] = fopen('11.txt', 'r');
% linecount = 0;
% lines_in_file = 0;
% while ~feof(fid)
% thisline = fgetl(fid);
% if ~ischar(thisline); break; end
% linecount = linecount +1;
% num_nonspace = nnz(~isspace(thisline));
% if num_nonspace >0
% lines_in_file = linecount;
% end
% end
% disp(linecount);
% LC = linecount-1;
% omega = double(LC);
%omega = LC
omega = load('11.txt') % input the data
omega = 10×1
0.9968 0.9964 0.9972 0.9966 0.9970 0.9970 0.9964 0.9966 0.9964 0.9966
t0x = 1/SpS; % determine tau from samples per second, SpS (entered at top)
t0 = double(t0x);
thetax = cumsum(omega, 1)*t0;
theta = double(thetax);
%display(theta);
%display(t0);
%display(omega);
maxNumM = 1000000;
L = size(theta, 1);
display(theta);
theta = 10×1
0.0399 0.0797 0.1196 0.1595 0.1994 0.2392 0.2791 0.3190 0.3588 0.3987
maxM = 2.^floor(log2(L/2));
m = logspace(log10(1), log10(maxM), maxNumM).';
m = ceil(m); % must be Integer Value
m = unique(m); % remove duplicates
display(L);
L = 10
tau = m*t0;
%disp(m);
avar = NaN(numel(m), 1); % create a matrix of zeros to speed up memory access
for i = 1:numel(m)
mi = m(i);
avar(i,:) = sum((theta(1+2*mi:L) - 2*theta(1+mi:L-mi) + theta(1:L-2*mi)).^2, 1);
end
avar = avar ./ (2*tau.^2 .* (L - 2*m));
disp(avar);
1.0e-06 * 0.1078 0.0269 0.0393 0.0615
adev = sqrt(avar);
disp(adev);
1.0e-03 * 0.3284 0.1641 0.1982 0.2480

Categorías

Más información sobre Time Series Events en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by