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
2 views (last 30 days)
Show older comments
% 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 Comments
Answers (1)
Voss
on 18 Mar 2022
Edited: Voss
on 18 Mar 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
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);
disp(adev);
0 Comments
See Also
Categories
Find more on Sensor Models in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!