How do I add gaussian noise with mean=0 and var=0.5 to a signal?
5 views (last 30 days)
Show older comments
Matteo Svaldi
on 19 Jul 2022
Commented: Star Strider
on 19 Jul 2022
I need to add a gaussian noise that has mean=0 and var=0.5 to a signal. The code i tried is below
F0=30;
T=0:0.01:4.99;
std= sqrt(0.5);
noise = std.*randn(length(T),1);
S=sin(2*pi*F0*T)+noise;
plot(T,S)
For some reason the plot is strange. Can anybody see where the mistake is?
0 Comments
Accepted Answer
Star Strider
on 19 Jul 2022
F0=30;
T=0:0.01:4.99;
std= sqrt(0.5);
noise = std.*randn(length(T),1);
S=sin(2*pi*F0*T)+noise % 'noise' Is A Column Vector Here
figure
plot(T,S)
It appears tto be strange because ‘S’ created a matrix, not the vector you were likely expecting. Beginning with R2016b, MATLAB has used ‘autoomatic explicit expansion’ so adding a row vector (‘sin(2*pi*F0*T)’) to the ‘noise’ column vector created the matrix. (In previous versions, this would have thrown an error.)
If you create ‘noise’ as a row vector, the result is:
S=sin(2*pi*F0*T)+noise.' % 'noise' Is A Row Vector Here
figure
plot(T,S)
.
2 Comments
More Answers (0)
See Also
Categories
Find more on Measurements and Feature Extraction 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!
