I am doing phase shift keying of binary data.
This is what I am doing,
f=10;
m=[];
b = [1 0 0 1 1 1 0]
for i=1:1:length(b)
if (b(i)==1)
Modulated=10*cos(2*pi*f*t2);
else
Modulated=10*cos(2*pi*f*t2 + pi);
end
m=[m Modulated];
end
The phase is not changing when there is a difference from last bit to present bit or present bit to future bit.
How can I change the phase when there is a difference in the bit value?
Edit: The pic with complete system. I am using equiripple filter.
Your code works fine. Maybe frequency is too high and a plot is too dense so that you can't notice it. Try with lower frequency.
Here is a code for (simplified) full modulation and demodulation:
%% modulation
f=0.5;
t2 = 0:0.01:1;
m=[];
b = [1 0 0 1 1 1 0];
for i=1:1:length(b)
if (b(i)==1)
Modulated=10*cos(2*pi*f*t2);
else
Modulated=10*cos(2*pi*f*t2 + pi);
end
m=[m Modulated];
end
subplot(3, 1, 1)
plot(m)
title('Modulated')
%% downconversion
oscillator = cos(2*pi*f*t2);
demod = m .* repmat(oscillator, 1, length(b));
subplot(3, 1, 2)
plot(demod)
title('Downconverted')
%% demodulation
d = [];
for i = 1:1:length(b)
idx_start = (i - 1) * length(t2) + 1;
idx_end = i * length(t2);
Demodulated = mean(demod(idx_start:idx_end));
d = [d Demodulated];
end
subplot(3, 1, 3)
plot(d, 'x')
title('Demodulated (LPF)')
And please be noted that, even though signal 1 and signal 0 are continuous, it does not mean that they have the same phase.