I have two vectors. One is of noise and one is of my signal. If I want to add noise vector to signal vector how can i do it. My noise dimension is 41001x1 and my signal is 88200x1.
-
2Why not add a random vector of the same size as the signal ? Also you should provide a minimal and reproducible example, check: How to create a Minimal, Reproducible Exampleobchardon– obchardon2020-12-24 09:15:16 +00:00Commented Dec 24, 2020 at 9:15
-
I cant. I am suppose to only add these two vectorsSyed Sheheryar Umair– Syed Sheheryar Umair2020-12-24 09:33:48 +00:00Commented Dec 24, 2020 at 9:33
-
1Then you need to explain how it should be done ! Matlab can not sum two vectors of different length.obchardon– obchardon2020-12-24 09:44:26 +00:00Commented Dec 24, 2020 at 9:44
1 Answer
Here is the code to product a signal and noise of the dimensions you mentioned:
time = (1:88200)';
sig = sin(0.005 * time);
noise = 0.1 * randn(41001, 1);
Since you cannot add two vectors of the same length, I chose to replicate the noise signal by repeating it so that it is the same length as sig:
multiplier = ceil(length(sig) / length(noise));
noise = repmat(noise, multiplier, 1);
noise = noise(1:length(sig));
Now the noise and sig are the same length they can be added and plotted together
plot(time, noise + sig)
In this answer, I'm assuming that noise and sig have the same sample rate, but noise is just too short for some reason. If the noise signal is at a different sample rate, then you would want to use interp1 or resample to get the same sample rate and number of points.