0
我想通過比較它同時記錄的LVDT位移來驗證一些加速器數據。要做到這一點,我試圖區分兩次LVDT數據以獲得加速度。然而,當我運行我的代碼有錯誤Matlab沒有處理第二個for循環
Undefined function or variable 'DiffDiffLVDT'.
調查這我發現Matlab的不處理第二個for循環,因此變量DiffDiffLVDT是從來沒有。
爲什麼跳過第二個循環?
enter code here
clear all
clc
test2 = csvread('HZ1.csv'); %raw data from excel
time = test2(:,1);
%% Filtering
f=250;% sampling frequency
f_cutoff = 2; % cutoff frequency
f_cutoff2 = 5;
fnorm =f_cutoff/(f/2); % normalized cut off freq, you can change it to any value depending on your requirements
fnorm2 =f_cutoff2/(f/2);
[b1,a1] = butter(4,fnorm,'low'); % Low pass Butterworth filter of order 4
[b2,a2] = butter(4,fnorm2,'low'); % Low pass Butterworth filter of order 4
filtaccZ = filtfilt(b2,a2,test2(:,6));
filtLVDTZ = filtfilt(b1,a1,test2(:,7));
%% Remove Offset
Accz = filtaccZ -mean(filtaccZ);
LVDTz = filtLVDTZ - mean(filtLVDTZ);
%% Unit Conversion
LVDTm = LVDTz/1000; % mm to m
%% LVDT Displacement to Acc
% Displacement to Velocity
for d = 2:1:(size(LVDTm)-1)
x = LVDTm(d+1);
y = LVDTm(d-1);
z = x-y; %differnce in y
a = time (d+1);
b = time (d-1);
c = a-b; %differnce in x
DiffLVDT(d)= (z/c); % Displacement to velocity
end
velocity = DiffLVDT;
% Velocity to Acceleration
for e=1:1:(size(velocity)-1)
x2 = velocity(e+1);
y2 = velocity(e-1);
z2 = x2-y2; %differnce in y
a2 = time (e+1);
b2 = time (e-1);
c2 = a2-b2; %differnce in x
DiffDiffLVDT(e)= (z2/c2) %velocity to acc.
end
Acc= DiffDiffLVDT
%% Plotting
close all
figure
hold on
plot(time(1:5000),Acc(1:5000),'b')
plot(time(1:5000),Accz(1:5000),'r')
grid on;box on
legend('DiffDiffLVDTFilter','Accz')
enter code here
這正是我想要的和數據完美匹配。非常感謝您的幫助。 – user2213349 2013-03-26 22:58:51
@ user2213349不客氣。請不要忘記接受答案。 – erikced 2013-03-27 07:50:49