Adding noise to a PID signal
48 views (last 30 days)
Show older comments
Hi everyone, As the title says I have created a PID system, and am attempting to add random noise over the created signal, but am unsure how to create the noise in this instance as it is not a normal function. Any advice or tips on how do add noise in this domain is greatly appreiated. Code is shown below
clear % housekeeping
clc % housekeeping
num= [1] % num of transfer function
denom= [1 3 1] % denom of transfer function
gp= tf(num, denom) % transfer function
h= [1] ; % feedback
m_nocontroller=feedback(gp, h)
step(m_nocontroller)
hold on
kp=3;
ki=0;
kd=0;
gc=pid(kp, ki, kd)
mc=feedback(gc*gp, h)
step(mc)
grid on
0 Comments
Answers (1)
Pat Gipper
on 31 Mar 2022
Hi Nathan,
You can use the lsim command to get a general response of your controller. I think you want to see the response when there is noise added to the input command. The code snippet below will do this for you.
t=(0:.001:7)';% time vector
u=ones(size(t));% input vector
n=randn(size(t));% Normal distributed samples
y=lsim(mc,u+n,t);% System response to step + random noise
% Plot PID response to unit step with added noise
figure;plot(t,y);grid
Sometimes the noise is added in at a separate point in the system as a disturbance. For example, it might be a disturbance that is added after the PID controller. But you would need to re-create your system object with the second input to do this.
1 Comment
Sam Chak
on 31 Mar 2022
Thank you for the suggested solution to plot the noise-contaminated system output.
Since the output measurement is contaminated by noise, it will affect the PID controller output signal as well. Would you advise @Nathan Ross on how to plot the noise-contaminated PID control signal for a linear system as well?
See Also
Categories
Find more on PID Controller Tuning in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!