📄 fh_2fsk.m
字号:
% function fh_ss
clc
clear,close all;
fs=200000;
T=0.005;
% message to be transmitted
signal1=randint(1,5,2);
msg1=signal1
signal1=2*signal1-1;
% selected frequencies
f=0:1/T:7/T;
f0=9000;
f1=f0+length(f)/T;
% address make
gen=[1 1 0 1]; % sv(j)=4[(a(j)+v0)mod2]+2[(a(j+1)+v1)mod2]+[(a(j+2))mod2]
address=address_make(gen)
add1=address(1,:);
add2=address(2,:);
add3=address(3,:);
add4=address(4,:);
add5=address(5,:);
%
sig1=ones(fs*T,1)*signal1;
sig1=sig1(:)';
%% modulation
% method one
% carrier
% carrier=[];
% for i=1:length(signal1)
% if signal1(i)==-1
% carrier=[carrier cos(2*pi*f0/fs*(0:T*fs-1))];
% else
% carrier=[carrier cos(2*pi*f1/fs*(0:T*fs-1))];
% end
% end
% % carrier modulation
% signal11=ones(T*fs,1)*signal1;
% signal11=signal11(:);
% signal11=signal11';
% tx1=signal11.*carrier;
% figure
% subplot(311),plot(signal11)
% subplot(312),plot(carrier)
% subplot(313),plot(tx1)
% % hopping modulation
% fh1=[];
% for i=1:length(signal1)
% fh1=[fh1 cos(2*pi*f(add1(i))/fs*(0:T*fs-1))];
% end
% tx1=tx1.*fh1;
% b=fir1(200,[9000*2/fs,(f1+f(8))*2/fs]);
% tx11=filter(b,1,tx1);
% figure,
% subplot(211),plotpp(tx1,fs)
% subplot(212),plotpp(tx11,fs)
% method two
carrier=[];
for i=1:length(signal1)
if signal1(i)==-1
carrier=[carrier cos(2*pi*(f0+f(add1(i)+1))/fs*(0:T*fs-1))];
else
carrier=[carrier cos(2*pi*(f1+f(add1(i)+1))/fs*(0:T*fs-1))];
end
end
signal11=ones(T*fs,1)*signal1;
signal11=signal11(:);
signal11=signal11';
tx11=signal11.*carrier;
% figure,
% subplot(211),plotpp(tx11,fs)
% subplot(212),plot(tx11)
%
ff0=300; % 中频
d_carrier0=[];
d_carrier1=[];
for i=1:length(signal1)
d_carrier0=[d_carrier0 cos(2*pi*(f0+ff0+f(add1(i)+1))/fs*(0:T*fs-1))];
d_carrier1=[d_carrier1 cos(2*pi*(f1+ff0+f(add1(i)+1))/fs*(0:T*fs-1))];
end
tx1_0=tx11.*d_carrier0;
tx1_1=tx11.*d_carrier1;
% figure
% subplot(411),plot(tx1_0)
% subplot(412),plot(tx1_1)
% subplot(413),plotpp(tx1_0,fs)
% subplot(414),plotpp(tx1_1,fs)
b=fir1(500,2000*2/fs);
tx1_0=filter(b,1,tx1_0);
tx1_1=filter(b,1,tx1_1);
% figure
% subplot(411),plot(tx1_0)
% subplot(412),plot(tx1_1)
% subplot(413),plotpp(tx1_0,fs)
% subplot(414),plotpp(tx1_1,fs)
R=ceil(fs/2000);
fss=fs/R*2;
tx1_0=decimate(tx1_0,R/2);
tx1_1=decimate(tx1_1,R/2);
% figure
% subplot(411),plot(tx1_0)
% subplot(412),plot(tx1_1)
% subplot(413),plotpp(tx1_0,fs)
% subplot(414),plotpp(tx1_1,fs)
tx1_0=reshape(tx1_0,length(tx1_0)/length(msg1),length(msg1));
tx1_0=tx1_0';
tx1_1=reshape(tx1_1,length(tx1_1)/length(msg1),length(msg1));
tx1_1=tx1_1';
len=length(tx1_0(1,:));
u1=cos(2*pi*ff0/fss*(0:len-1));
v1=sin(2*pi*ff0/fss*(0:len-1));
% 求初值
for i=1:length(msg1);
r1c(i,1)=tx1_0(i,1)*u1(1);
r1s(i,1)=tx1_0(i,1)*v1(1);
r2c(i,1)=tx1_1(i,1)*u1(1);
r2s(i,1)=tx1_1(i,1)*v1(1);
end
% 积分
for i=1:length(msg1);
for k=2:len;
r1c(i,k)=r1c(i,k-1)+tx1_0(i,k)*u1(k);
r1s(i,k)=r1s(i,k-1)+tx1_0(i,k)*v1(k);
r2c(i,k)=r2c(i,k-1)+tx1_1(i,k)*u1(k);
r2s(i,k)=r2s(i,k-1)+tx1_1(i,k)*v1(k);
end
end
% 抽样判决
for i=1:length(msg1);
r1(i)=r1c(i,len)^2+r1s(i,len)^2;
r2(i)=r2c(i,len)^2+r2s(i,len)^2;
end
for i=1:length(msg1);
if r1(i)>=r2(i);
msg_demod1(i)=0;
else msg_demod1(i)=1;
end
end
msg_demod1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -