文档库 最新最全的文档下载
当前位置:文档库 › 调制解调matlab程序

调制解调matlab程序

clear;
clear all;
%调制信号
fs=100000;
fm=1000;
dt=1/fs;
t=0:dt:0.01;
mt=cos(2*pi*fm*t);
subplot(2,1,1);
plot(t,mt);grid on;
title('调制信号mt=cos(pi*t)的波形');



%载波信号
fc=10000;
Ct=cos(2*pi*fc*t);
subplot(2,1,2);
plot(t,Ct);
title('载波信号波形');
figure;


%writed by zhangchenglong


%AM调制
A=1;
SAM=(A+mt).*Ct;
subplot(3,1,1);
plot(t,SAM);grid on;hold on;
plot(t,A+mt,'r');
axis([0 0.01 -2 2]);
title('AM调制后的波形');



%DSB调制
DSB=mt.*Ct;
subplot(3,1,2);
plot(t,DSB,'b');grid on;
axis([0 0.01 -2 2]);
title('dsb调制后的波形');



subplot(3,1,3);
plot(t,mt);
axis([0 0.01 -2 2]);
title('调制信号');
figure;



%SSB相移法
SSB1=(1/2)*mt.*Ct+(1/2)*sin(2*pi*fm*t).*sin(2*pi*fc*t);%下边带
SSB2=(1/2)*mt.*Ct-(1/2)*sin(2*pi*fm*t).*sin(2*pi*fc*t);%上边带



%对各信号求频谱做fft变换
N=2048; %采样频率和数据点数
n=0:N-1; t=n/fs; %时间序列
y=fft(mt,N); %对信号进行快速Fourier变换
mag=abs(y);
y1=fft(Ct,N);
mag1=(abs(y1));
y2=fft(DSB,N);
mag2=(abs(y2));
y3=fft(SAM,N);
mag3=(abs(y3));
y4=fft(SSB1,N);
mag4=(abs(y4));
y5=fft(SSB2,N);
mag5=(abs(y5));
f=n*fs/(1000*N); %频率序列
subplot(321);
plot(f,mag); %绘出随频率变化的振幅
axis([0 20 0 400]);
title('调制信号频谱');
xlabel('频率/kHz');
ylabel('振幅');grid on;
subplot(322);
plot(f,mag1);
axis([0 20 0 400]);
title('载波信号频谱');
xlabel('频率/kHz');
ylabel('振幅');grid on;
subplot(323);
plot(f,mag2);
axis([0 20 0 400]);
title('DSB已调信号频谱');
xlabel('频率/kHz');
ylabel('振幅');grid on;
subplot(324);
plot(f,mag3);
axis([0 20 0 400]);
title('AM已调信号频谱');
xlabel('频率/kHz');
ylabel('振幅');grid on;
subplot(325);
plot(f,mag4);
axis([0 20 0 400]);
title('SSB已调下边带信号频谱');
xlabel('频率/kHz');
ylabel('振幅');grid on;
subplot(326);
plot(f,mag5);
axis([0 20 0 400]);
title('SSB上边带已调信号频谱');
xlabel('频率/kHz');
ylabel('振幅');grid on;
figure;


%绘制低通滤波器频率响应
wc=1.5*2*pi*fm/fs;
N=1000;
B=fir1(16,wc/pi);
[h,w]=freqz(B, 1, N);
x=w*fs/(2*pi)/1000;
y=20*log10(abs(h));
B;
plot(x,y);grid on;
axis([0 40 -100 0]);
xlabel('k/hz');
title('低通滤波器的频率相应');
figure;

%对DSB乘法器输出和解调器输出做频谱分析并得到输出信号
h=DSB.*Ct;
N=2048; %采样频率和数据点数
n=0:N-1; t=n/fs; %时间序列
h1=fft(h,N); %对信号进行快速Fourier变换
mag=abs(h1);
f=n*fs/(1000*N); %频率序列
subplot(311);
plot(f,mag);
axis([0 22 0 200]);
title('解调乘法器输出信号频谱');
xlabel('频率/kHz');
ylabel('振幅');grid on;

%cross the lpf
fs=100000;
dt=1/fs;
t=0:dt:0.01;
h2=filter(B,1,h);
subplot(312);
pl

ot(t,h2);grid on;
title('DSB解调信号');

%对解调器输出做fft变换
N=2048; %采样频率和数据点数
n=0:N-1;t=n/fs; %时间序列
y=fft(h2,N); %对信号进行快速Fourier变换
mag=abs(y); %求得Fourier变换后的振
f=n*fs/(1000*N); %频率序列
subplot(313);
plot(f,mag); %绘出随频率变化的振幅
axis([0 22 0 200]);
title('解调器输出信号频谱');
xlabel('频率/kHz');
ylabel('振幅');grid on;
figure;


%同频但不同相时输出信号
fs=100000;
dt=1/fs;
t=0:dt:0.01;
Ct1=cos(2*pi*fc*t+pi/8);
h=DSB.*Ct1;

%cross the lpf
h2=filter(B,1,h);
subplot(221);
plot(t,h2);grid on;
axis([0 0.01 -0.5 0.5]);
title('DSB解调相位差pi/8信号');

Ct1=cos(2*pi*fc*t+pi/4);
h=DSB.*Ct1;
h2=filter(B,1,h);
subplot(222);
plot(t,h2);grid on;
axis([0 0.01 -0.5 0.5]);
title('DSB解调相位差pi/4信号');

Ct1=cos(2*pi*fc*t+pi/3);
h=DSB.*Ct1;
h2=filter(B,1,h);
subplot(223);
plot(t,h2);grid on;
axis([0 0.01 -0.5 0.5]);
title('DSB解调相位差pi/3信号');

Ct1=cos(2*pi*fc*t+pi/2);
h=DSB.*Ct1;
h2=filter(B,1,h);
subplot(224);
plot(t,h2);grid on;
axis([0 0.01 -0.5 0.5]);
title('DSB解调相位差pi/2信号');








相关文档
相关文档 最新文档