CodexBloom - Programming Q&A Platform

MATLAB 'lsim' function returns NaN for specific input signals in R2023b

👀 Views: 63 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-17
MATLAB control-systems signal-processing

I've encountered a strange issue with I'm working with an scenario with the `lsim` function in MATLAB R2023b where it returns NaN for certain input signals... My system is defined by a simple transfer function, and I'm trying to simulate its response to a sinusoidal input. Here's the relevant code snippet: ```matlab num = [1]; % Numerator coefficients den = [1, 2, 1]; % Denominator coefficients sys = tf(num, den); % Create transfer function t = 0:0.01:10; % Time vector u = sin(t); % Sinusoidal input [y, t_out, x] = lsim(sys, u, t); % Simulate system response ``` However, when I run this, the output `y` contains NaN values for the entire duration of `t_out`. I've verified that the transfer function is valid, and I even tried changing the input to a constant value, which worked fine. I also checked the time vector to ensure it's properly defined. I've tried various input signals, such as a step function and a ramp, and they work as expected. It's only the sinusoidal input that fails. I've also looked into the system's stability and confirmed that the poles are located in the left half of the s-plane. Are there any specific conditions or configurations that I might be missing when using `lsim` with sinusoidal inputs? Could it potentially be related to the frequency of the sine wave? Any insights or suggestions would be greatly appreciated! My development environment is Windows 11. Any ideas what could be causing this?