please, how can i make the plot on the x axis from 15 to 25 hertz to rest on the x axis. that is to make them start from zero. i have used detrend but, it is not working

Hello can you help with the above question

9 Kommentare

Share your data and the code you have tried. You can paste your code into your post. You can attached your data using the paperclip icon after you save your variable to a mat file.
close all; clear ; clc;
fs= 1000;
T=7;
dt= 1/fs;
tspan= (0:dt:T).';
load acc.mat
yddot = acc;
ydot = detrend(cumtrapz(tspan,yddot));
y = detrend(cumtrapz(tspan,ydot));
m = 1;
f0 = [1:0.1429:25];
w0 = 2*pi*f0;
for ii =1:length(w0)
k = w0(ii)^2*m;
cr = 2*sqrt(k*m); %critical damping
% c= 1.5;
for c = 1.5:1:5.5
dr= c/cr; %damping ratio
mc = 3;
M = [m 0;
0 mc ];
Nff = 1;
mff = M(1:Nff,1:Nff);
% mff=[m1 0; 0 m2];
cff = c;
cfc = -c;
kff = k;
kfc = -k;
A = [-inv(mff)*cff -inv(mff)*kff; eye(Nff) zeros(Nff)];
B = [-cfc -kfc; zeros(Nff,1) zeros(Nff,1)];
x0 = zeros(2*Nff,1);
options= odeset ('RelTol',1e-6, 'AbsTol', 1e-9);
[t,x ] = ode45(@(t,x) myFun(t,x,A,B,y,ydot,fs),tspan,x0 ,options);
x1 = x(:,2);
xdot1 = x(:,1);
zdot = (xdot1 - ydot);
Energy(ii) = (trapz(tspan,c*(zdot).^2));
end
end
figure (50)
plot(f0,abs((Energy)))
ylabel('Energy harvested in Joules')
xlabel ('Natural frequency (Hz)')
% legend ('C=1.5', 'C=2.5', 'C=3.5', 'C=4.5', 'C=5.5')
xlim([0, 26])
%
Two things i want to do;
  1. i want the plot from 15 to 25 to come down a bit, just as the plot from 0 to 10 on the x axis.
  2. i want to vary the damping coefficient from 1.5 to 5.5 and plot the energy harvested fro c= 1.5 to 5.5 on the same graph.
thank you
Can you share myFun function?
Please how can i interpolate the time steps in this function?
the ODE 45, is not using the exact time step i fed into it?
function dx = myFun(t,x,A,B,y,ydot, fs)
ind = round(t*fs)+1;
u = [ydot(ind); y(ind)];
dx = A*x + B*u;
We need to see how your ode45 syntax to be able to answer that question. The relevant section of the documentation can be found here: https://www.mathworks.com/help/matlab/ref/ode45.html#bu00_4l_sep_shared-tspan
If you specify a vector a timepoints for tspan, ode45 will return solutions at those time points. If that is not close enough, you can use interp1. There is an anwer from 2012 about that: https://www.mathworks.com/matlabcentral/answers/92961-how-do-i-use-a-fixed-step-size-with-ode23-and-ode45-in-matlab
Note - that post mentions the interpolation feature was added in MATLAB 5. We are now on MATLAB 9.
Thank you. i have been able to fix the interpolation but it is very slow. How do i make it faster.
We are several steps removed from the original question. I suggest asking a new question in the forum.
some of the data i dropped are from an ongoing research, which i should not have dropped

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

This is likely due to the resolution of your data. The signal is not able to capture everything, so over time, the error accumulates. There are likely techniques you can use when collecting the data to minimize this. However, since you already have the signal, I think you should try higher-order detrending. Here I picked 10 based solely on how the ouput looks
fs= 1000;
T=7;
dt= 1/fs;
tspan= (0:dt:T).';
load acc.mat
yddot = acc;
ydot = cumtrapz(tspan,yddot);
ydot2 = detrend(ydot,10,"SamplePoints",tspan);
y = cumtrapz(tspan,ydot2);
plot(tspan,ydot2,tspan,y)

2 Kommentare

Another approach might be to smooth your signal and then subtract the smoothed signal from the raw signal.
fs= 1000;
T=7;
dt= 1/fs;
tspan= (0:dt:T).';
load acc.mat
yddot = acc;
ydot_raw = cumtrapz(tspan,yddot);
smoothedData = smoothdata(ydot_raw,"lowess","SmoothingFactor",0.125);
ydot = ydot_raw - smoothedData;
y = cumtrapz(tspan,ydot);
plot(tspan,ydot,tspan,y)
Post that was deleted
Thank you very much for your response. what of the other question i asked? did you figured it out also?
______________________________________________________________________
Response
It seems you already have the code written for that, but you are only capturing the final result from your nested for loops.
You can capture it easily enough. You just need to make Energy a matrix instead of a vector.
Change
for c = 1.5:1:5.5
...
Energy(ii) = (trapz(tspan,c*(zdot).^2));
end
to something like
dcoeffs = 1.5:1:5.5;
for jj = 1:length(dcoeffs)
c = dcoeffs(jj);
...
Energy(ii,jj) = (trapz(tspan,c*(zdot).^2));
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by