二进制频移键控(2FSK)
1 基本原理
1.1 BFSK基本原理
1.2 成形滤波器的设计
推荐用FDATOOL,而不建议使用函数。
Response-cosine:选择raised-cosine;
Fs:程序中的采样频率
Fc:截止频率,其值为码速率的一半。程序中码速率Rb=1MHz,所以这里为0.5。
Rolloff:滚降系数,一半选择0.35。
function Hd = fdatool_shape_filter
%FDATOOL_SHAPE_FILTER Returns a discrete-time filter object.
% MATLAB Code
% Generated by MATLAB(R) 9.5 and DSP System Toolbox 9.7.
% Generated on: 26-Nov-2021 10:26:05
% FIR Window Raised-cosine filter designed using the FIRRCOS function.
% All frequency values are in MHz.
Fs = 200; % Sampling Frequency
N = 300; % Order
Fc = 0.5; % Cutoff Frequency
TM = 'Rolloff'; % Transition Mode
R = 0.35; % Rolloff
DT = 'Normal'; % Design Type
Beta = 0.5; % Window Parameter
% Create the window vector for the design algorithm.
win = kaiser(N+1, Beta);
% Calculate the coefficients using the FIR1 function.
b = firrcos(N, Fc/(Fs/2), R, 2, TM, DT, [], win);
Hd = dfilt.dffir(b);
% [EOF]
2 源代码
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 2FSK调制与解调(加成形滤波器)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all;
clear all;
clc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 参数设置
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fs=200e6; % 采样频率
Ts=1/fs; % 采样周期
f1=10e6; % FSK信号的信号频率f1
f2=20e6; % f2
%----------码元相关参数
N=20; % 码元个数
Rb=1e6; % 码速率
Tb=1/Rb; % 码元周期
count=fs/Rb; % 一个码元的采样点数
n=count*N; % 总的采样点数
t=0:1/fs:(n-1)/fs; % 信号持续时间
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 1、产生基带信号
% 一个码元取count个点
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%-----s1=1,s2就为0; s1=0,s2就为1;
s_I=randi([0,1],1,N); % I路 单极性序列
s_Q=mod(s_I+1,2); % Q路
st_I=zeros(1,n);
st_Q=zeros(1,n);
for p = 1:length(s_I) % 内插count个点
st_I( ((p-1)*count+1) : (p*count) ) = s_I(p);% 对应的周期为Tb
st_Q( ((p-1)*count+1) : (p*count) ) = s_Q(p);% 对应的周期为Tb
end
figure(1)
subplot(221)
stem(s_I);hold on;
ylim([-1.2,1.2]);
xlabel('时间/s');ylabel('幅度');
title('基带信号');
subplot(222)
plot(t,st_I);hold on;
ylim([-1.2,1.2]);
xlabel('时间/s');ylabel('幅度');
subplot(223)
stem(s_Q);hold on;
ylim([-1.2,1.2]);
xlabel('时间/s');ylabel('幅度');
subplot(224)
plot(t,st_Q);hold on;
ylim([-1.2,1.2]);
xlabel('时间/s');ylabel('幅度');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 成形滤波
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 法一:调用函数
%%%%%% [yf,tf]=rcosine(Fd,Fs,'fir/sqrt',R,Delay)
% % Fd (Hz):输入数字序列的采样率
% % Fs (Hz):滤波器的采样频率 Fs/Fd 必须是一个正整数
% % TYPE_FLAG指定滤波器的选型或者设计
% % R :roll-off factor 指定滤波器的过渡频带
% % DELAY :从滤波器的开始到脉冲响应峰值的时间延迟,必须为一个正整数
%%% DELAY的值越大,则滤波器的阶数越多,基带成型滤波后的信号越光滑
%%% 阶数N=delay*(Fs/Fd)*2+1
% DELAY=1;
% R=0.5;
% % [yf,tf]=rcosine(Fd,fs,'fir/sqrt',R,Delay); % 根升余弦
% [yf,tf]=rcosine(Rb,fs,'fir/normal',R,DELAY); % 升余弦
%---------法二:利用fdatool(推荐)
% FIR Window Raised-cosine filter designed using the FIRRCOS function.
% All frequency values are in MHz.
Fs = 200; % Sampling Frequency
N = 300; % Order
Fc = 0.5; % Cutoff Frequency ********码速率的一半************
TM = 'Rolloff'; % Transition Mode
R = 0.35; % Rolloff
DT = 'Normal'; % Design Type
Beta = 0.5; % Window Parameter
% Create the window vector for the design algorithm.
win = kaiser(N+1, Beta);
% Calculate the coefficients using the FIR1 function.
yf = firrcos(N, Fc/(Fs/2), R, 2, TM, DT, [], win);
x1_I=conv(yf,st_I); % 滤波
x1_Q=conv(yf,st_Q);
L_bandpass=length(yf); % 滤波器系数的长度
delay_shape=(L_bandpass-1)/2; % 滤波器的延时
x2_I=x1_I( delay_shape+1:1:(end-delay_shape) );
x2_Q=x1_Q( delay_shape+1:1:(end-delay_shape) );
%----幅度谱
L=length(x2_I);
f=(0:L-1)*fs/L-fs/2;
P_x2_I=fftshift(fft(x2_I));
P_x2_Q=fftshift(fft(x2_Q));
P_x2_I=abs(P_x2_I)/L;
P_x2_Q=abs(P_x2_Q)/L;
figure(2);
subplot(221)
plot(t,x2_I);hold on;grid on;
xlabel('时间/s');ylabel('幅度');
title('成形滤波后的I路信号');
subplot(222)
plot(f/1e6,P_x2_I);hold on;grid on;
xlabel('频率/MHz');ylabel('幅度');
subplot(223)
plot(t,x2_Q);hold on;grid on;
xlabel('时间/s');ylabel('幅度');
title('成形滤波后的Q路信号');
subplot(224)
plot(f/1e6,P_x2_Q);hold on;grid on;
xlabel('频率/MHz');ylabel('幅度');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 3、BFSK信号调制
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BFSK_signal=x2_I.*cos(2*pi*f1*t)+x2_Q.*cos(2*pi*f2*t);
%----幅度谱
P_BFSK_signal=fftshift(fft(BFSK_signal));
L=length(P_BFSK_signal);
P_BFSK_signal=abs(P_BFSK_signal)/L;
f=(0:L-1)*fs/L-fs/2;
figure(3)
subplot(211)
plot(t,BFSK_signal);hold on;grid on;
xlabel('时间/s');ylabel('幅度');
title('2FSK信号');
subplot(212)
plot(f/1e6,P_BFSK_signal);hold on;grid on;
xlabel('频率/MHz');ylabel('幅度');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 4、 2FSK解调
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%------------4.1 带通滤波 f1通过,f2截止
% All frequency values are in MHz.
Fs = 200; % Sampling Frequency
N = 400; % Order
Fstop1 = 5; % First Stopband Frequency
Fpass1 = 8; % First Passband Frequency
Fpass2 = 12; % Second Passband Frequency
Fstop2 = 15; % Second Stopband Frequency
Wstop1 = 1; % First Stopband Weight
Wpass = 1; % Passband Weight
Wstop2 = 1; % Second Stopband Weight
dens = 20; % Density Factor
% Calculate the coefficients using the FIRPM function.
b_bandpass = firpm(N, [0 Fstop1 Fpass1 Fpass2 Fstop2 Fs/2]/(Fs/2), [0 0 1 1 0 ...
0], [Wstop1 Wpass Wstop2], {dens});
y31_t=conv(BFSK_signal,b_bandpass);
L_bandpass=length(b_bandpass); % 滤波器系数的长度
delay_bandpass=(L_bandpass-1)/2; % 滤波器的延时
y41_t=y31_t( (delay_bandpass+1):1:(end-delay_bandpass) );
%----幅度谱
P_y41_t=fftshift(fft(y41_t));
P_y41_t=abs(P_y41_t)/L;
%------------4.2 带通滤波 f2通过,f1截止
% All frequency values are in kHz.
Fs = 200; % Sampling Frequency
N = 400; % Order
Fstop1 = 15; % First Stopband Frequency
Fpass1 = 18; % First Passband Frequency
Fpass2 = 22; % Second Passband Frequency
Fstop2 = 25; % Second Stopband Frequency
Wstop1 = 1; % First Stopband Weight
Wpass = 1; % Passband Weight
Wstop2 = 1; % Second Stopband Weight
dens = 20; % Density Factor
% Calculate the coefficients using the FIRPM function.
b_bandpass = firpm(N, [0 Fstop1 Fpass1 Fpass2 Fstop2 Fs/2]/(Fs/2), [0 0 1 1 0 ...
0], [Wstop1 Wpass Wstop2], {dens});
y32_t=conv(BFSK_signal,b_bandpass);
L_bandpass=length(b_bandpass); % 滤波器系数的长度
delay_bandpass=(L_bandpass-1)/2; % 滤波器的延时% 解调
y42_t=y32_t( (delay_bandpass+1):1:(end-delay_bandpass) );
%----幅度谱
P_y42_t=fftshift(fft(y42_t));
P_y42_t=abs(P_y42_t)/L;
figure(4)
subplot(221)
plot(t,y41_t);grid on;
xlabel('时间/s');ylabel('幅度');
title('带通滤波后的I路信号 ');
subplot(222)
plot(f,P_y41_t);hold on;grid on;
xlabel('频率/Hz');ylabel('幅度');
subplot(223)
plot(t,y42_t);grid on;
xlabel('时间/s');ylabel('幅度');
title('带通滤波后的Q路信号 ');
subplot(224)
plot(f,P_y42_t);hold on;grid on;
xlabel('频率/Hz');ylabel('幅度');
%------------4.3 相干解调
y51_t=y41_t.*cos(2*pi*f1*t);
y52_t=y42_t.*cos(2*pi*f2*t);
%----幅度谱
P_y51_t=fftshift(fft(y51_t));
P_y52_t=fftshift(fft(y52_t));
L=length(P_y51_t);
f=(0:L-1)*fs/L-fs/2;
P_y51_t=abs(P_y51_t)/L;
P_y52_t=abs(P_y52_t)/L;
figure(5)
subplot(221)
plot(t,y51_t);grid on;
xlabel('时间/s');ylabel('幅度');
title('相干解调后的I路信号 ');
subplot(222)
plot(f,P_y51_t);hold on;grid on;
xlabel('频率/Hz');ylabel('幅度');
subplot(223)
plot(t,y52_t);grid on;
xlabel('时间/s');ylabel('幅度');
title('相干解调后的Q路信号 ');
subplot(224)
plot(f,P_y52_t);hold on;grid on;
xlabel('频率/Hz');ylabel('幅度');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 6 低通滤波(滤掉2*f1=20M,2*f2=40M),得到信号s1_t,s2_t
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% All frequency values are in MHz.
Fs = 200; % Sampling Frequency
N = 50; % Order
Fpass = 10; % Passband Frequency
Fstop = 15; % Stopband Frequency
Wpass = 1; % Passband Weight
Wstop = 1; % Stopband Weight
dens = 20; % Density Factor
% Calculate the coefficients using the FIRPM function.
b1 = firpm(N, [0 Fpass Fstop Fs/2]/(Fs/2), [1 1 0 0], [Wpass Wstop], ...
{dens});
y61_t=conv(y51_t,b1); % 低通滤波(滤掉2*f1=600k)
y62_t=conv(y52_t,b1); % 低通滤波(滤掉2*f2=1000k)
L_filter=length(b1); % 滤波器系数的长度
delay=(L_filter-1)/2; % 滤波器的延时
y71_t=y61_t( (delay+1):1:(end-delay) );
y72_t=y62_t( (delay+1):1:(end-delay) );
%----幅度谱
P_y71_t=fftshift(fft(y71_t));
P_y72_t=fftshift(fft(y72_t));
P_y71_t=abs(P_y71_t)/L;
P_y72_t=abs(P_y72_t)/L;
figure(6)
subplot(221)
plot(t,y71_t);grid on;
xlabel('时间/s');ylabel('幅度');
title('低通滤波后的信号 ');
subplot(222)
plot(f,P_y71_t);hold on;grid on;
xlabel('频率/Hz');ylabel('幅度');
subplot(223)
plot(t,y72_t);grid on;
xlabel('时间/s');ylabel('幅度');
title('低通滤波后的信号 ');
subplot(224)
plot(f,P_y72_t);hold on;grid on;
xlabel('频率/Hz');ylabel('幅度');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 7 抽样判决
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
y1_n=y71_t(count/2:count:end); % 抽样
y2_n=y72_t(count/2:count:end); % 抽样
yn=zeros(1,length(y2_n));
for p=1:length(y1_n)
if(y1_n(p)>y2_n(p))
yn(p)=1;
else
yn(p)=0;
end
end
figure(7)
stem(s_I,'-r*');hold on;
stem(yn,'-bo');hold on;
ylim([-1.2,1.2]);grid on;
legend('发送序列','接收序列');
xlabel('时间/s');ylabel('幅度');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 8、 误码率计算
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sum_error=0;
for p=1:length(yn)
if(yn(p)~=s_I(p))
sum_error=sum_error+1;
end
end
fprintf('错误的码元个数为%g\n',sum_error);
3 结果