Adding noise to a PID signal

18 views (last 30 days)
Nathan Ross
Nathan Ross on 18 Mar 2022
Commented: Sam Chak on 31 Mar 2022
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

Answers (1)

Pat Gipper
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
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?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by