# Road profile, car model, suspension model

26 Ansichten (letzte 30 Tage)
Mattia Abrate am 10 Mär. 2022
Beantwortet: Divyanshu am 4 Mär. 2024
Hi everyone I made this MATLAB code in order to generate random road profiles starting from the corresponding PSD value:
psi0=1;
plot1=1;
L=100;
L1=0; %start length of the road
L2=L1+L; %end of the road (m)
psi0=psi0*10^-6;
omega1=.01; %low cutoff wavenumber for PSD
omega2=100; %high cutoff wavenumber
delta=omega1; %step size
N=((omega2-omega1)/delta)+2; %number of points in PSD plot
omega=linspace(omega1,omega2,N); %psd plot wavenumber range
psi=zeros(1,N); %initialize PSD
Ns=100; %number of samples in one meter of road profile
a=zeros(1,N); %initialize amplitude
phi=rand(1,N)*2*pi; %random angles
W=2; %waviness
psi(1:N)=psi0*(omega(1:N).^(-W)); %Calculate PSD
a(1:N)=(2*psi(1:N)*(delta)).^(1/2); %Calculate amplitude
for i=1:Ns*L2
for j=1:N
z(i)=(a(j)*sin((omega(j)*s(i))-phi(j)))+z(i);
end
end
z(1:Ns*L2)=z(1:Ns*L2)-z(1); %fix initial conditions to 0
if plot1==1
figure
subplot(2,1,1);
loglog(omega,psi)
subplot(2,1,2);
plot(s,z*100);
set(gcf,'color','w');
end
The code works pretty nicely and here is an example of an obtained plot:
Now, I'm trying to use it as an input for the suspension simulink model, I used the blocks: MATLAB function and interpreted MATLAB functions, in both the cases, the solving time is really high and the plot I obtained has the following form:
It looks as Simulink is not able to interprete the for cycle and it recalculates the whole profile for each time step, also if I run the model again I obtain always the same output, while in MATLAB I obtain a different profile every time I run the code.
Can someone help me to solve this??
Thanks,
Mattia
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Divyanshu am 4 Mär. 2024
Hi Mattia,
I created a dummy model, with only MATLAB Function Block and placed the above code inside the block.
On Simulation, I was able to get multiple different profiles correctly as expected. Therefore, the Simulation with MATLAB Function block is working as desired and probably the other parts/blocks of the Suspension model are affecting the final plot.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu General Applications finden Sie in Help Center und File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by