# Adding sine signal to dynamic signal

2 views (last 30 days)
Nurullah Çetin on 26 Dec 2021
Commented: William Rose on 26 Dec 2021
y(t) = x(t-10) + sin(t) I need to create the solution for this dynamic signal, I couldnt delay the signal that I have created randomly. Would you mind to help?
signal_length= 0:0.5:100;
rng(1);
xt=rand(1,length(signal_length));
plot(signal_length,xt,'color','r','linewidth',1.5)
grid on
xlabel('t','FontSize',10)
ylabel('x(t)', 'FontSize',10)
figure
t=0:0.5:100;
rng(1);
xt=rand(1,length(signal_length));
delayed_xt= delayseq(xt,10);
plot(t,delayed_xt,'color','r','linewidth',1.5)
grid on
xlabel('t','FontSize',10)
ylabel('x(t-10)', 'FontSize',10)
t= -20:0.5:100;
w_sin= 2*pi/30;
sint= sin(w_sin*t);
figure
plot(t,sint,'color','r','LineWidth',1.5)
axis([0 100 -1 1])
grid on
xlabel('t','fontSize',10)
ylabel('sint(t)','FontSize',10)
grid on
t1= 0:0.5:100;
xlabel('t','fontSize',10)
ylabel('sint(t)','FontSize',10)
yt=delayed_xt+sint(41:length(sint));
figure
plot(t1,yt,'color','r','LineWidth',1.5)
xlabel('t','fontSize',10)
ylabel('y(t)','FontSize',10)
grid on

William Rose on 26 Dec 2021
dt=0.5; %time step (s)
t=0:dt:100; %time (s)
tlag=10; %lag (s)
x=rand(1,length(t));
y=zeros(1,length(t)); %pre-allocate y
y(tlag/dt+1:end)=x(1:end-tlag/dt); %y=x(t-tlag)
figure;
plot(t,x,'-r.',t,y,'-b.');
grid on; legend('x','y'); xlabel('Time (s)'); Try it.
What would you expect the cross-correlation of x with y to look like? This is a way of checking to see if the script above worked as expected. Let's see:
[xc,lags] = xcorr(x,y,40,'normalized');
stem(lags*dt,xc)
xlabel('Time lag (s)'); title('CrossCorr(x,y)') Interesting, and reassuring.
##### 2 CommentsShowHide 1 older comment
William Rose on 26 Dec 2021
I'm sorry that I do not understand your description of what you want x(t) and y(t) to be. My script computes x(t) and y(t) according to the equations
x(t) = noise
and
y(t) = x(t-10) + sin(t)
The second equation above is the equaiton you provided in your original posting. If either equation above is incorrect, please provide the correct equations.