MATLAB Answers


Add a varying phase shift to a sine wave (linspace involved)

Asked by Andrew
on 12 Mar 2014
Latest activity Commented on by Andrew
on 12 Mar 2014
I have created a sine wave using the linspace function (see below), and using that wave and another one at a different frequency I have created an FSK signal by adding them together. Now I want to add another sine signal to this FSK signal but with a varying phase shift in order to simulate a fading channel.
ask1 = sin(linspace(0,2*pi*f1*transmission_time,total_samples));
So far I was just able to add a signal with a constant phase shift therefore my channel is not realistic enough and that is why I want to introduce a varying phase shift. The code used for the constant phase shift follows:
fade_sig = sin(linspace(0,2*pi*f1*transmission_time,total_samples) - (pi));
Some limitations are that I do not want to change the linspace function use in order to create the sine wave, as it is a vital component to my program because of the use of samples(total_samples) in order to create graphs and produce good results. Some ideas are the use of for loops and pre-creating a vector of phase shift and then using that to add it to the signal but seems too complicated to implement because of the use of the linspace function. Is there a easier method that I can approach this issue.
Thank you in advance Andrew


Sign in to comment.

1 Answer

Answer by Adeola Bannis on 12 Mar 2014
 Accepted Answer

I think you should be able to get what you want by pre-creating a vector of phase shifts. As long as it is the same shape (column vs row, and length) as the original signal, it should work.
For example:
sample_times = linspace(0,2*pi*f1*transmission_time,total_samples);
ask1 = sin(sample_times);
r = linspace(-0.2, 0.2, total_samples);
fade_sig = sin(sample_times + r);
This is what I get when I plot ask1 and fade_sig:


Thank you for your fast response. By a few adjustments I got what I pretty much wanted. Thank you for guiding me through the right path!
um, Note that when you form a sum of two such vectors, both of which are linear sequences, you do NOT get a phase shift!!! A phase shifted series should have the same frequency as the old series. Note that the plots as shown do NOT. My point is, this answer does NOT provide a uniform phase shift.
Dear John,
I don't exactly understand what you mean, but after some tests with just this part of my program I am getting what I want. And even in the main program the code seems to work fine, I am getting bit errors after decoding the fsk signal due to the fact that sometimes the signal with frequency f1 has been cancelled out due to this fading signal( which at some point it will be at 180 out of phase) causing these desirable wrong decisions in the decoder. Let me demonstrate using the following code:
z = (1:10000);
total_samples = 10000;
transmission_time = 5;
sample_times = linspace(0,2*pi*f1*transmission_time,total_samples);
ask1 = sin(sample_times);
r = linspace(-2*pi, 2*pi, total_samples);
fade_sig = sin(sample_times + r);
final = ask1 + fade_sig;
The following graphs are obtained:
and the resultant signal is :
Which is what I pretty much want, a signal with fades and amplifications which is what a fading channel cause due to multipath propagation.

Sign in to comment.