bpsk_decode.m

来自「BPSK_QPSK代码」· M 代码 · 共 45 行

M
45
字号
function code_output=bpsk_decode(bpsk_input,frequency)
%Demodulation  BPSK
%code_output is output of BPSK demodulation 
%bpsk_input is a sequence of modulation  signal
%frequency is carrier frequency
%Author is lipeng
%date:2008 11 15
%Example:
%code_output=bpskd_decode([1 0 1 1 0],2)

clc;
if nargin > 2
    error('Too many input arguments');
elseif nargin==1
    frequency=1;
elseif nargin==0
    error('There should be one input argument at lest!');
end
if frequency<1;
    error('Frequency must be bigger than 1');
end
t=0:2*pi/(100*frequency-1):2*pi;
sub=[];
cp=[];
b=[];
code_output=[];
band_singnal=sin(frequency*t);
for n=1:length(bpsk_input)/length(band_singnal)
    sub=bpsk_input((n-1)*length(band_singnal)+1:n*length(band_singnal));
    cp=sub.*band_singnal;
    b=(1/2+sum(cp)/length(band_singnal))*ones(1,100*frequency);
    code_output=[code_output b];
end
subplot(8,1,3);
plot(bpsk_input,'LineWidth',1.5);
grid on;
title('BPSK demodulation');
axis([0 length(bpsk_input) -2.5 2.5]); 

subplot(8,1,4);
plot(code_output,'LineWidth',1.5);
grid on;
title('Binary Signal');
axis([0 length(bpsk_input) -2.5 2.5]);
clc;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?