how can i get the quantized signals for different velocities?and how i will get position errors
1 回表示 (過去 30 日間)
古いコメントを表示
this is the code i am having. format long; clear all; close all; %DECLARATION OF VARIABLES dt = 50e-9; % time stamp resolution [1/s] v = 10; % angular velocity Here for V a const value is given...how to give rage of vaues [10,300].. A = 0.05; % amplitude f = 500; % frequency [Hz] te = 0.002; % ending time t = [0:dt:te]; % time vector inc = 400; % encoder resolution dx = 1; % encoder step rsp = 1e-4; % sample period n = (te/dt)+1; % number of time samples o = 2; % order of polynomial fit nts = 5; % numbers of timestamp control_time = 0:rsp:te; % control time instants err_f_vector = []; % xfit - xreal err_q_vector = []; % xquan - xreal x = zeros(n,1); % simulated real signal x1 = zeros(n,1); % extra real signal for plotting xq = zeros(n,1); % simulated quantized signal xq1 = zeros(n,1); % extra quantized signal for plotting xf = zeros(1,n); % estimated signal TS = []; % time stamp array XS = []; % position array controlinstant_vector = []; % sample times array RMS_value = []; % rms error estimation RMS_value2 = []; % rms error quantization %PROGRAM EXECUTING %constructing real signal for i=1:n x1(i) = (v*t(i)+A*sin(2*pi*f*t(i)))*(inc/(2*pi)); xq1(i)= round(x1(i)/dx)*dx end
%quantization + polynomial fitting i=0; for i=1:n x(i) = (v*t(i)+A*sin(2*pi*f*t(i)))*(inc/(2*pi)); xq(i)= round(x(i)/dx)*dx; if i ~= 1 if length(TS) >= nts TS = TS(:,2:nts); XS = XS(:,2:nts); end if round(x(i)/dx) ~= round((x(i-1))/dx) ts = t(i); TS = [TS ts]; if round(x(i)/dx) > round((x(i-1))/dx) xs = (xq(i)-0.5*dx); XS = [XS xs]; end if round(x(i)/dx) < round((x(i-1))/dx) xs = (xq(i)+0.5*dx); XS = [XS xs]; end end if length(TS) == nts cf = coefflu(TS,XS,o,nts) xf = polyval(cf,t); controlinstant_ = (floor((i*dt)/rsp) + 1)*rsp; controlinstant__vector = [controlinstant__vector controlinstant_]; controlinstant__i = int32(((floor((i*dt)/rsp) + 1)*rsp)/dt + 1); err_f = ((x1(controlinstant__i) - polyval(cf,controlinstant_))); err_f_vector = [err_f_vector err_f]; err_q = ((x1(controlinstant__i) - xq1(controlinstant__i))); err_q_vector = [err_q_vector err_q]; plotapprox(t,x1,xq1,TS,XS,xf,control_time); end if i==n TS = []; XS = []; timer = 0.0; end end end RMS_value = [RMS_value rms(err_f_vector)]; RMS_value2 = [RMS_value2 rms(err_q_vector)]; ploterror(controlinstant__vector, err_f_vector, err_q_vector, dx);
0 件のコメント
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!