Hello, I wanted to simulate a signal which has noise in the form of spikes (both positive and negative). If a single IF condition is inserted, one can easily generate positive spikes of desired height. Suppose we also wish to insert an additional condition that if n (i) <0, we get a negative spike of magnitude -0.5 in the noise. I have tried several approaches but the vector size of noise increases if I include a separate IF condition. What would be an appropriate way to incorporate both outcomes of IF in one vector with the same size as "t"? Thanks.
t=0:0.01:20;x=normpdf(t, 10, 0.1); % Gaussian peak
n=rand(1,length(t));noise=[];for i=1:length(t) if(n(i)>=1) noise=[noise 1.5]; else noise=[noise 0]; endendx=x+noise;
Best Answer