Adding Phase shift to sum of sines
5 views (last 30 days)
Show older comments
Matlab code for summation of two signals with phase shift
I am writing a code for a summation of two signals. The only part I need help in is in the addition of the phase shift which would be piecewise since it is a phase shift of three different time sections. The original problem statement is shown below that was used to create the Matlab code. The part I am stuck in is for developing the code for the phi(t) which is three different time sections. My code and plot without the phase shift are shown after the original problem statement. How do I add the phi(t) to my code. t in this case is x. Thanks in advance.
Original problem statement
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1172153/image.png)
My matlab code and plot without phase shift
f1 = 0.98e9;
f2 = 1.02e9;
w1 = 2*pi*f1;
w2 = 2*pi*f2;
wo = (w1+w2)/2;
wm = (w2-w1)/2;
x = 0:.05e-9:50e-9;
m = abs(20*cos(wm*x));
vo = m.*cos(wo*x);
plot(x,vo,'r')
xlabel('t')
ylabel('Vo(t)')
title('Alternative plot of two signal summation')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1172158/image.png)
0 Comments
Answers (1)
Shoaib iqbal
on 31 Oct 2022
Hi Jose,
I understand that you are trying to add two sinusoids with phase shift.
You can try to make an array corresponding to phi(x), where ‘x’ is same as time steps you have specified. The total number of samples in your case is 1001 (0:0.05ns:50ns). The phi(x) is given as
Phi(x) = 0 for 0 < x < 12.5 ns
Phi(x) = pi for 12.5 ns < x < 37.5 ns
Phi(x) = 0 for 37.5 ns < x < 50 ns
12.5 ns corresponds to 251th sample, similarly 37.5 ns corresponds to 751th sample. The following code snippet creates phi(x) and Vout(x)
Phi = zeros(1,1001);
Phi(251:750) = pi;
Vout = m.*cos(wo*x + Phi);
Hope this solves your query.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!