Adding Noise to Signal through Rand function?

Hello everyone, I just want a simple help as I am new to matlab.
I want to add Noise to my Signal through rand function but its giving error. Kindly if anyone can see how am i doing it wrong. Thoguh its just few lines from a long code which works perfectly without this noise addition.
noise = 2*rand (size(time));
y2t=noise+y22t; // y22t is the signal
plot(time*1e9,y2t,'-k','LineWidth',2);
xlabel('Time - [ns]');ylabel('Amplitude - [V]');
hold on;
grid on;

 Respuesta aceptada

Image Analyst
Image Analyst el 10 de Abr. de 2020
Editada: Image Analyst el 10 de Abr. de 2020
Try this:
t = 1 : 50; % Whatever.
y22t = 2 * sin(2 * pi * t / 15);
subplot(2, 1, 1);
plot(t, y22t, 'b-', 'LineWidth', 2);
grid on;
xlabel('Time - [ns]', 'FontSize', 15);
ylabel('ytt', 'FontSize', 15);
title('Noise-free y22t', 'FontSize', 15);
noise = 2*rand (size(t)); % To go on both sides of the signal, use 2*rand (size(t)) - 1
y2t=noise+y22t; % y22t is the signal
subplot(2, 1, 2);
plot(t,y2t,'-k', 'LineWidth',2);
xlabel('Time - [ns]', 'FontSize', 15);
ylabel('Amplitude - [V]', 'FontSize', 15);
title('Noisy y22t', 'FontSize', 15);
hold on;
grid on;
Don't use time as the name of your variable since it's the name of a built-in function.

2 comentarios

Syed Adeel
Syed Adeel el 10 de Abr. de 2020
@image Analyst Thankyou so much for your to the point reply.
I got your point and tried it in code. Just a bit more of querry
% To go on both sides of the signal, use 2*rand (size(t)) - 1
First, Is that 2 the amplitude or something else?
Secondly, y2t was my output of the code but in actual i need to add the bandwidth liimited with mean value 0 noise at the input stage which is "x1s":
%%% Plot in Time-Domain %%% %%% %%% %%% %%% %%% %%% %%% %%% %%% %%% %%% %%%
syms t;
to1=1e-9;
to2=to1+QTIME;
%%% Input Signal Laplace Transform
x1s=(exp(-s*to1))*1/s-(exp(-s*to2))*(1/s); % This is the input
I=Q/QTIME;
x1s=I*x1s;
x1t=ilaplace(x1s);
ys1=x1s*tfvout1; % tfvout1 is the trasfer function of system from which i calculate the output
Can you help with it?
Image Analyst
Image Analyst el 11 de Abr. de 2020
Yes, 2 is the amplitude of the noise. It can be whatever you want.
Sorry I can't help with the second part. I don't have the Symbolic Toolbox and haven't dealt with Lalace Transforms since I was an undergraduate many decades ago.

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2016a

Preguntada:

el 10 de Abr. de 2020

Comentada:

el 11 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by