Why I get different values when I integrate a function like integrating velocity to get Displacement but the result gradally decreases to negative while velocity is gradually increasing

1 view (last 30 days)
Hai all,
this program is regarding my dissertation, it is to know the response of a floating body for the generated wave of given amplitude and frequency. The above program is plotted based on the obtained data for the body's vertical or heave motion for 10mm amplitude and 0.6hz frequency wave. I have plotted the graph for acceleration vs time, acceleration vs frequency and so on. Moreover i applied a bandpass filter to cancel out unwanted noise to get accurate results. upon filtering, my graphs for acceleration vs time, velocity vs time occurs to be increasing with the given time period of 60 seconds starting from zero, while plotting the obtained displacement through cumtrapz function, my graph seems to be fluctuating or decreasing with time. This is really confusing
%%%%%%%%%%CODE FOR 10MM AMPLITUDE 0.6Hz FREQUENCY%%%%%%%%%%%%%%%%%%%%%%%
clc
close all
clear all
opts = detectImportOptions("SenseLog-10mm06hz"); %to read the file
opts.VariableTypes{8} = "datetime"; %to seperate date and time
opts = setvaropts(opts,"timestamp","InputFormat","yyyy-MM-dd HH:mm:ss.SSSSSS");
t = readtable("SenseLog-10mm06hz",opts); %reading the new data
t.elapsedTime = t.timestamp-t.timestamp(1); % to know the difference between time intervals
t.elapsedTime.Format = "s"; %to convert the time in seconds
Time = seconds(t.elapsedTime); %A(:,12);%assingng the time bin
Ts1 = mean(diff(Time)); %to find the mean value of the time period
Fs1 = 1/Ts1; % to find the sampling frequency
Fn = Fs1/2; % nyquest frequency
x = t.accel_x; %assigning the x direction values to x bin
y = t.accel_y; %assigning the y direction values to y bin
z= t.accel_z; %assigning the Z direction vales to z bin
Acc= x; %reading it a acceleration
figure()
plot (Time,Acc);%plotting time and acceleration
grid on;
xlim([0 60]);%limiting the value
xlabel('time in sec');%time in sec in the x-axis
ylabel('acceleration');%Acceleration in cm/sec^2 in the y-axis
L=length(Time); %to read the whole data in the time coloum
Y = fft(Acc); %taking the fast fourier transform
P2 = abs(Y/L); %taking the absolute value of Y/L
P1=P2(1:L/2+1);%dump half to get single sided spec /2 except for first and last
P1(2:end-1)=2*P1(2:end-1);%double magnitudes
freq=Fs1*(0:(L/2))/L;% now create frequency vector
figure()
plot(freq,P1)
grid on;
%ylim([0 0.005])
xlabel('frequency')
ylabel('Acceleration')
order = 3; %applying filter of order 3
fcutlow = 0.59;%limit for the lower band filter
fcuthigh = 0.61;%limit for the higher band filter
[b,a]=butter(order,[fcutlow,fcuthigh]/(Fs1/2),'bandpass');%to initialise filter
filtsig=filter(b,a,Acc);%naming the filtered data
Y2 = fft(filtsig);%taking the fast fourier transform
P22 = abs(Y2/L);%taking the absolute value of Y2/L
P12=P22(1:L/2+1);%dump half to get single sided spec /2 except for first and last
P12(2:end-1)=2*P12(2:end-1);%double magnitudes
figure()
plot(freq,P12)%code for plotting
grid on;
xlim([0 1.3])%giving limit to x-axis
xlabel('Freq')%label for x-axis
ylabel('Accel - AMP')%label for y-axis
title('After filter')%title for the plot
figure();
plot(Time,filtsig)%code for plotting
grid on;
xlim([0 60])%giving limit to x-axis
xlabel('Time')%label for x-axis
ylabel('Acceleration')%label for y-axis
title('After filter')%title for the plot
j=filtsig.*9.81;%converting to m/s^2
velocity=cumtrapz(Time,j);%To find the cumulative
velocity1=velocity-mean(velocity); % allow for non-zero start
figure();
plot(Time,velocity1)%code to plot
grid on;
xlim([0 60])%giving limit to x-axis
xlabel('Time')%x-axis label
ylabel('velocity in m/s')%y-axis label
title('After filter')%title for plot
disp=cumtrapz(Time,velocity1);%to find the cumulative
disp1 = disp-mean(disp); % allow for non-zero start
figure()
plot(Time,disp1) % code to plot
xlim([0 60])%giving limit to x-axis
xlabel('Time')%x-axis label
ylabel('displacement m')%y-axis label
title('After filter')%title for plot
figure()
plot(Time,filtsig,'r',Time,velocity1,'g',Time,disp1,'b');%code for plotting
grid on;
xlim([0 60])%giving limit to x-axis
xlabel('time')%label for x-axis
ylabel('accel, vel, and disp')%label for y-axis
legend('Acceleration in m/s^2','Velocity in m/s','Displacement in m')

Answers (0)

Community Treasure Hunt

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

Start Hunting!