Search code examples
matlabnoise

add white guassian noise to data with matlab


I am trying to solve an state estimation problem for the power grid. In the power grid, there are measurement devices which measure some quantities like voltage magnitude, power flow from lines, etc and send them to the control center. I have an state estimation code written in matlab, which gets these measurements as input and determines the states of the grid. So, I want to create a measurement set for the grid. I have a set of noise-free measurements and I want to add guassian noise to them with an specific standard deviation (say 5%). How can I do that? What does this 5% standard deviation mean (the percent is relative to what?) Thanks for your help in advance


Solution

  • You can check the concept of standard deviation at:

    https://en.wikipedia.org/wiki/Standard_deviation

    You can do this using randn or awgn, see:

    https://es.mathworks.com/help/comm/ref/awgn.html

    https://es.mathworks.com/help/matlab/ref/randn.html

    Here is an example test that I think can be adjusted to what you are looking for:

    close all
    A=1; %Amplitude
    p=5; %Deviation percentage
    n=4;
    x = linspace(0,n*pi,1000);
    y=A*sin(x);
    figure;
    plot(x,y)
    %Adding Noise
    
    DesiredSD = A*p/100;                               % the desired standard deviation
    noise=DesiredSD*randn(1,1000);
    y_gaussian_noise =y+noise;
    y_g=y+awgn(y,p,'measured');
    figure;
    plot(x,noise);
    figure;
    plot(x,y,x,y_gaussian_noise,x,y_g,'linewidth',1.2);
    xlabel('Time(s)');
    ylabel('Signal');
    legend('without noise', 'with noise','awgn generator');