您的代码工作正常。也许频率太高,情节太密集,以至于你无法注意到它。尝试较低频率。
这是(简化的)全调制和解调的代码:
%% 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)')
请注意,即使信号1和信号0是连续的,也不意味着它们具有相同的相位。