How to get range of values from a plot?
조회 수: 10 (최근 30일)
이전 댓글 표시
Hi,
Firstly, I am doubful about getting velocity and acceleration using 'gradient' function instead of 'diff' to get velocity and acceleration from displacement 'y2' in time domain.Is it the correct way to do? secondly, I am trying to get specific range of values from my graph but have no idea how to do?
For example, I just want values in time domain with 0 to 2.5 in x-axis or in between 2.5 to 10, and interpolate to get the perfect nearest one in time axis? I want such portion because I want to add another section of graph from free vibration analysis, this the the response using forced vibration only.
Thanks
Here is my code:
clear all
close all
clc
a=0.5;beta=0.025;wb=14.25;gamma = 1e-10; % introduce gamma
% Define time and frequency axis variables
fs =400; % samples/s
N = 1e6; % number of points
dt = 1 / fs; % s, time step
t = (0:N-1)*dt; % s, time axis
df = 1 / N / dt; % Hz, frequency step
f = (-N/2:N/2-1)*df; % Hz, frequency axis
eta_dom=0.15:0.1:1;
len_eta=length(eta_dom);
len_f=length(f);
X_store=zeros(len_eta,len_f);
% Define function first mode
for j=1:len_eta
eta=eta_dom(j)
y3=sin(pi.*a).*eta.*(1+exp(-1i.*pi.*f./eta))./((-f.^2+(2.*1i).*f.*beta+1).*(eta.^2-i*f*gamma-f.^2));
y4=sin(pi.*a).*eta.*(1+exp(-1i.*pi.*f./eta))./((-f.^2+(2.*1i).*f.*beta+1).*(eta.^2+i*f*gamma-f.^2));
yy = (y3+y4)/2;
%plot original signal
figure(1)
% plot initial time domain signal
plot(f,yy),title('Frequency response');ylabel('Displacement Response of beam');xlabel('Frequency');
grid on
%conversion to time domain
y2 = ifft(ifftshift(yy));
X_store(j,:)=y2;
figure(2)
plot(t,(y2)),title('Time response');ylabel(' Displacement Response of beam');xlabel('Time');hold on;
axis([0 2.5 -0.03 0.03]); % time domain signal after IFFT
grid on
%% To calculate velocity and acceleration
v=gradient(y2);
acc=gradient(v);
figure(3),plot(t,(v)),title('Time response');ylabel('velocity Response of beam');xlabel('Time');hold on;
axis([0 2.5 -0.001 0.001]);
figure(4),plot(t,(acc)),title('Time response');ylabel('acceleration Response of beam');xlabel('Time');%hold on;
axis([0 2.5 -0.00002 0.00002]);
end
figure(5)
cmap=[jet(9)];
for k=1:9
plot(t,X_store(k,:),'color',cmap(k,:),'linewidth',1.5);axis([0 0.7 -0.03 0.03]); hold on;colorbar
end
hold off;
댓글 수: 6
채택된 답변
Thiago Henrique Gomes Lobato
2021년 4월 18일
The difference between gradient and diff is that the first calculates central differences and the second forward differences, both should give you an approximated right differentiation, although their numerical stabilities are different. In your case it shouldn't matter too much. Specifically for the case of displacement, velocity and acceleration, what is often done is a differentiation/integration in frequency domain. This can be done by multiplying/dividing your spectrum by 1j*w, where w = 2*pi*f.
If you only want the values between 0 and 2.5 s or any other interval you can find the respectively values by using logic indexing like this:
a=0.5;beta=0.025;wb=14.25;gamma = 1e-10; % introduce gamma
% Define time and frequency axis variables
fs =400; % samples/s
N = 1e6; % number of points
dt = 1 / fs; % s, time step
t = (0:N-1)*dt; % s, time axis
startTime = 0;
endTime = 2.5;
validIndices = find(t>startTime & t<endTime);
tTruncated = t(validIndices);
y2Truncated = t(validIndices);
validIndices
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Optimization Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!