%SSB信号调制解调%希尔伯特变换法产生(相移法)clear;clc;f0=1;%信源信号频率(Hz)E0=1;%信源信号振幅(V)E=1;%载波分量振幅(V)fc=10;%载波分量频率(Hz)t0=1;%信号时长snr=15;%解调器输入信噪比dBdt=0.003;%系统时域采样间隔fs=1/dt;%系统采样频率df=0.001;%所需的频率分辨率t=0:dt:t0;Lt=length(t);%仿真过程中,信号长度snr_lin=10^(snr/10);%解调器输入信噪比%-------------画出调制信号波形及频谱%产生模拟调制信号m=E*cos(2*pi*f0*t);L=min(abs(m));%包络最低点R=max(abs(m));%包络最高点%画出调制信号波形和频谱clf;figure(1);%%%画出调制信号波形subplot(421);plot(t,m(1:length(t)));axis([0,t0,-R-0.3,R+0.3]);%设置坐标范围xlabel('t');title('调制信号');set(gca,'YTick',-R:1:R);subplot(422);[M,m,df1,f]=T2F_new(m,dt,df,fs);%求出调制信号频谱[Bw_eq]=signalband(M,df,t0);%求出信号等效带宽plot(f,fftshift(abs(M)));%画出调制信号频谱%M:傅里叶变换后的频谱序列xlabel('f');title('调制信号频谱');axis([-fc-5*f0,fc+5*f0,0,max(M)+0.3]);set(gca,'XTick',-10:10:10);set(gca,'XGrid','on');%%%载波及其频谱subplot(423);c=cos(2*pi*fc*t);%载波plot(t,c);axis([0,t0,-E-0.2,E+0.2]);xlabel('t');title('载波');subplot(424);%载波频谱[C,c,df1,f]=T2F_new(c,dt,df,fs);plot(f,fftshift(abs(C)));%画出载波频谱xlabel('f');title('载波频谱');axis([-fc-5*f0,fc+5*f0,0,max(C)+0.3]);set(gca,'XTick',-10:10:10);set(gca,'XGrid','on');%%sm_low=1/2*cos(2*pi*f0*t).*cos(2*pi*fc*t)+1/2*sin(2*pi*f0*t).*sin(2*pi*fc*t);%下边带信号sm_high=1/2*cos(2*pi*f0*t).*cos(2*pi*fc*t)-1/2*sin(2*pi*f0*t).*sin(2*pi*fc*t);%上边带信号%%subplot(425);plot(t,sm_low(1:length(t)));axis([0,t0,-R-0.3,R+0.3]);%设置坐标范围xlabel('t');title('下边带信号');set(gca,'YTick',-R:1:R);[M_low,m_low,df1,f]=T2F_new(sm_low,dt,df,fs);%求出调制信号频谱[Bw_eq_low]=signalband(M_low,df,t0);%求出信号等效带宽subplot(426);plot(f,fftshift(abs(M_low)));%画出调制信号频谱%M:傅里叶变换后的频谱序列xlabel('f');title('下边带频谱');axis([-fc-5*f0,fc+5*f0,0,max(M_low)+0.3]);set(gca,'XTick',-10:10:10);set(gca,'XGrid','on');%%subplot(427);plot(t,sm_high(1:length(t)));axis([0,t0,-R-0.3,R+0.3]);%设置坐标范围xlabel('t');title('上边带信号');set(gca,'YTick',-R:1:R);[M_high,m_high,df1,f]=T2F_new(sm_high,dt,df,fs);%求出调制信号频谱[Bw_eq_high]=signalband(M_high,df,t0);%求出信号等效带宽subplot(428);plot(f,fftshift(abs(M_high)));%画出调制信号频谱%M:傅里叶变换后的频谱序列xlabel('f');title('上边带频谱');axis([-fc-5*f0,fc+5*f0,0,max(M_high)+0.3]);set(gca,'XTick',-10:10:10);set(gca,'XGrid','on');%%%将已调信号送入信道%先根据所给信噪比产生高斯白噪声figure(2);signal_power=power_x(sm_low(1:Lt));%已调信号的平均功率noise_power=(signal_power*fs)/(snr_lin*4*Bw_eq_high);%求出噪声方差(噪声均值为0)noise_std=sqrt(noise_power);%噪声标准差noise=noise_std*randn(1,Lt);%产生噪声%画出信道高斯白噪声波形及频谱,此时,噪声已实现,为确知信号,可求其频谱subplot(321);plot(t,noise);axis([0,t0,-max(noise),max(noise)]);xlabel('t');title('噪声信号');subplot(322);[noisef,noise,df1,f]=T2F_new(noise,dt,df,fs);%噪声频谱plot(f,fftshift(abs(noisef)));%画出噪声频谱xlabel('f');title('噪声频谱');%%%信道中的信号%叠加了噪声的已调信号频谱sam=sm_low(1:Lt)+noise(1:Lt);subplot(323);plot(t,sam);axis([0,t0,-max(sam),max(sam)]);xlabel('t');title('信道中的信号');subplot(324);[samf,sam,df1,f]=T2F_new(sam,dt,df,fs);%求出叠加了噪声的已调信号频谱plot(f,fftshift(abs(samf)));%画出叠加了噪声的已调信号频谱xlabel('f');title('信道中信号的频谱');axis([-fc-5*f0,fc+5*f0,0,max(samf)+0.1]);set(gca,'XTick',-10:10:10);set(gca,'XGrid','on');%%f_start_low=fc-Bw_eq_low;f_cutoff_low=fc;[H_low,f]=bp_f(length(sam),f_start_low,f_cutoff_low,df1,fs,1);%求带通滤波器subplot(325);plot(f,fftshift(abs(H_low)));%画出带通滤波器xlabel('f');title('带通滤波器');axis([-f_cutoff_low-1,f_cutoff_low+1,-0.05,1.05]);%%subplot(326);plot(f,fftshift(abs(H_low)));%画出带通滤波器xlabel('f');axis([-f_cutoff_low-1,f_cutoff_low+1,-0.05,1.05]);holdon;plot(f,fftshift(abs(samf)));%画出叠加了噪声的已调信号频谱title('信号经过带通滤波器');%%%----------------经过带通滤波器%经过理想滤波器后的信号及其频谱DEM=H_low.*M_low;%滤波器输出信号的频谱[dem]=F2T_new(DEM,fs);%滤波器输出信号的波形figure(3);subplot(321);%经过理想带通滤波器后的信号波形plot(t,dem(1:Lt));%画出经过理想带通滤波器后的信号波形axis([0,t0,-max(dem)-0.3,max(dem)+0.3]);xlabel('t');title('理想BPF输出信号');%%[demf,dem,df1,f]=T2F_new(dem(1:Lt),dt,df,fs);%求经过理想带通滤波器后的信号频谱subplot(322);plot(f,fftshift(abs(demf)));%画出经过理想带通滤波器后信号频谱xlabel('f');title('理想BPF输出信号频谱');axis([-fc-5*f0,fc+5*f0,0,max(demf)+0.1]);set(gca,'XTick',[-10:10:10]);set(gca,'XGrid','on');%%%--------------和本地载波相乘,即混频subplot(323);plot(t,c(1:Lt));axis([0,t0,-E-0.2,E+0.2]);xlabel('t');title('本地载波');subplot(324);%频谱载波[C,c,df1,f]=T2F_new(c(1:Lt),dt,df,fs);plot(f,fftshift(abs(C)));%画出载波频谱xlabel('f');title('本地载波频谱');axis([-fc-5*f0,fc+5*f0,0,max(C)+0.3]);set(gca,'XTick',[-10:10:10]);set(gca,'XGrid','on');%再画出混频后信号及其频谱der=dem(1:Lt).*c(1:Lt);%混频%%subplot(325);%画出混频后的信号plot(t,der);axis([0,t0,-R,R]);xlabel('t');title('混频后的信号');subplot(326);[derf,der,df1,f]=T2F_new(der,dt,df,fs);%求出混频后的信号频谱plot(f,fftshift(abs(derf)));%画出混频后的信号频谱xlabel('f');title('混频后的信号频谱');axis([-2*fc-5*f0,2*fc+5*f0,0,max(derf)+0.3]);set(gca,'XTick',[-10:10:10]);set(gca,'XGrid','on');%%%%figure(4);subplot(321);plot(t,m(1:Lt));%画出调制信号波形xlabel('t');title('调制信号');set(gca,'YTick',[-R:1:R]);axis([0,t0,-R-0.3,R+0.3])xlabel('t');title('调制信号');subplot(322);[M,m,df1,f]=T2F_new(m,dt,df,fs);%求出调制信号频谱[Bw_eq]=signalband(M,df,t0);%求出信号等效带宽plot(f,fftshift(abs(M)));%画出调制信号频谱%M:傅里叶变换后的频谱序列xlabel('f');title('调制信号频谱');axis([-fc-5*f0,fc+5*f0,0,max(M)+0.3]);set(gca,'XTick',-10:10:10);set(gca,'XGrid','on');%%%-----------------经过低通滤波器%画出理想低通滤波器[LPF,f]=lp_f(length(der),Bw_eq,df1,fs,1);%求出低通滤波器subplot(323);plot(f,fftshift(abs(LPF)));%画出理想低通滤波器xlabe