bpsk_code.m

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

M
61
字号
function bpsk_output=bpsk_code(code_input,frequency)
% Modulation  BPSK
% bpsk_output is output of BPSK modulation
% code_input is a sequence of digital signal
% frequency is carrier frequency
% Author is lipeng
% date:2008 11 15
% Example:
% bpsk_output=bpskd_code([1 0 1 1 0],2)

% code_input=[1 0 1 1 0 1 0 1 0 0 0 1 1 0 1];
% frequency=2;
% nargin=2;

clc;
if nargin > 2
error('Too many input arguments');
elseif nargin==1
    frequency=1;
elseif nargin==0
    code_input=[1 0 1 1 0 1 0 1 0 0 0 1 1 0 1];
    frequency=1;
end
if frequency<1;
    error('Frequency must be bigger than 1');
end
t=0:2*pi/(100*frequency-1):2*pi;
cp=[];
sp=[];
mod=[];
mod1=[];
bit=[];
for n=1:length(code_input);
    if code_input(n)==0; 
        die=-ones(1,100*frequency);   %Modulante
        se=zeros(1,100*frequency);    
    else code_input(n)==1;
        die=ones(1,100*frequency);    %Modulante
        se=ones(1,100*frequency);     
    end
    c=sin(frequency*t);
    cp=[cp die];    
    mod=[mod c];    
    bit=[bit se];
end

bpsk_output=cp.*mod;
subplot(8,1,1);
plot(bit,'LineWidth',1.5);
grid on;
title('Binary Signal');
axis([0 100*length(code_input)*frequency -2.5 2.5]);

subplot(8,1,2);
plot(bpsk_output,'LineWidth',1.5);
grid on;
title('BPSK modulation');
axis([0 100*length(code_input)*frequency -2.5 2.5]); 
%save 'bpsk_date.mat' bpsk_output;
%save 'bpsk_frequency' frequency;
clc;

⌨️ 快捷键说明

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