how to modify plot range from (-200 to 200)
조회 수: 2 (최근 30일)
이전 댓글 표시
% Define the mass, damping, and stiffness matrices
load C K
load M.mat
% Define the input force as a sinusoidal function of frequency w in Hz
f = linspace(0, 40, 100); % linearly spaced frequency vector in Hz
w = 2*pi*f; % angular frequency vector in rad/s
F = @(t) [sin(2*pi*f(1)*t); zeros(3, 1)];
% Define the initial conditions
x0 = zeros(4, 1);
v0 = zeros(4, 1);
y0 = [x0; v0];
% Define the time span
tspan = [0 20];
% Preallocate arrays to store the magnitude and phase of the response
mag = zeros(size(w));
phase = zeros(size(w));
% Loop over the frequency vector and compute the response at each frequency
for i = 1:length(w)
% Define the input force at the current frequency
F = @(t) [sin(w(i)*t); zeros(3, 1)];
% Solve the differential equation to obtain the steady-state response
[~, y] = ode45(@(t, y) vibration_equation(t, y, M, C, K, F), tspan, y0);
x = y(end, 1:4)';
% Compute the magnitude and phase of the response at the current frequency
mag(i) = abs(x(1));
phase(i) = angle(x(1)) * 180/pi;
end
% Plot the magnitude and phase of the FRF in Hz
figure;
subplot(2, 1, 1);
plot(f, mag);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Frequency Response Function');
grid on;
subplot(2, 1, 2);
plot(f, mod(phase+180,360)-180);
xlabel('Frequency (Hz)');
ylabel('Phase (deg)');
ylim([-180, 180]);
grid on;
function dydt = vibration_equation(t, y, M, C, K, F)
% Compute the acceleration
x = y(1:4);
v = y(5:8);
a = M \ (F(t) - C*v - K*x);
% Compute the derivative of the state vector
dydt = [v; a];
end
I want something like in shown in photo. from -200 to 200 range for phase graph.
댓글 수: 0
답변 (1개)
Cris LaPierre
2023년 3월 18일
편집: Cris LaPierre
2023년 3월 18일
The function angle already returns the phase angle on the interval of [,π], which you convert to degrees, or [-180,180]. For some reason, your angles are only negative. So I would first look into why the angles are between 0 and -180 before I'd modify the phase plot and data.
댓글 수: 3
Cris LaPierre
2023년 3월 18일
I don't think that is the correct approach. Consider looking at the bottom of this page to see what they do with a system with 4 degrees of freedom:
참고 항목
카테고리
Help Center 및 File Exchange에서 Spectral Measurements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!