📄 gen_ssb.m
字号:
function [x]=gen_ssb(fc,fs,fx,Ns,FLAG,SNR)
%产生ssb信号
%fc:carrier frequency
%fs:sampple frequency
%fx:bandwidth of message signal
%Ns:number of total samplles per segment
% FLAG == '+'? usb:lsb
%SNR:snr of signal received
luo=0.98;
n=randn(Ns,1);
xm=zeros(Ns,1);
for i=2:Ns
xm(i,:)=luo*xm(i-1)+n(i);
end;
%filt the message signal
Wn=fx/(fs/2);
fir_coef=fir1(30,Wn);
xm=fftfilt(fir_coef,xm);
%adjust the mean of message signal
xm = xm - mean(xm);
%ssb modulation
y=imag(hilbert(xm));
t=1:Ns;
if(FLAG=='lsb')
for t=1:Ns
s(t,1)=xm(t)*cos(2*pi*fc*t/fs)+y(t)*sin(2*pi*fc*t/fs);
end
else % generate usb
for t=1:Ns
s(t,1)=xm(t)*cos(2*pi*fc*t/fs)-y(t)*sin(2*pi*fc*t/fs);
end
end
%band limitation on modulated signal
if FLAG=='lsb'
Wn=[(fc-fx)/(fs/2),(fc)/(fs/2)];
Wn2=[(fc-1.2*fx)/(fs/2),(fc)/(fs/2)];
else
Wn=[(fc)/(fs/2),(fc+fx)/(fs/2)];
Wn2=[(fc)/(fs/2),(fc+1.2*fx)/(fs/2)];
end
% filter coefficient;
fir_coef = fir1(30, Wn);
s=fftfilt(fir_coef, s);
%%% adding the AWGN noise;
n=randn(Ns,1);
fir_coef2=fir1(30,Wn2);
n=fftfilt(fir_coef2,n);
Sp=sum(s.*conj(s));
Np=sum(n.*conj(n));
Rsn=sqrt(Sp/Np)*10^(-SNR/20);
%signal received
x=s+Rsn*n;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -