2ask调制解调matlab代码
时间: 2023-10-11 08:09:58 浏览: 113
2ASK调制解调的MATLAB代码如下:
调制代码:
```matlab
clc;
clear all;
close all;
am=input('Enter the message signal frequency:');
fm=input('Enter the amplitude of message signal:');
fc=input('Enter the carrier signal frequency:');
fs=input('Enter the sampling frequency:');
t=0:1/fs:1;
m=sin(2*pi*am*t)*fm;
c=sin(2*pi*fc*t);
s=(1+fm*sin(2*pi*am*t)).*c;
subplot(3,1,1);
plot(t,m);
title('Message signal');
xlabel('Time');
ylabel('Amplitude');
subplot(3,1,2);
plot(t,c);
title('Carrier signal');
xlabel('Time');
ylabel('Amplitude');
subplot(3,1,3);
plot(t,s);
title('2ASK modulated signal');
xlabel('Time');
ylabel('Amplitude');
```
解调代码:
```matlab
clc;
clear all;
close all;
am=input('Enter the message signal frequency:');
fm=input('Enter the amplitude of message signal:');
fc=input('Enter the carrier signal frequency:');
fs=input('Enter the sampling frequency:');
t=0:1/fs:1;
m=sin(2*pi*am*t)*fm;
c=sin(2*pi*fc*t);
s=(1+fm*sin(2*pi*am*t)).*c;
rec=s.*c;
[b,a]=butter(6,2*fc/fs);
y=filter(b,a,rec);
subplot(3,1,1);
plot(t,m);
title('Message signal');
xlabel('Time');
ylabel('Amplitude');
subplot(3,1,2);
plot(t,c);
title('Carrier signal');
xlabel('Time');
ylabel('Amplitude');
subplot(3,1,3);
plot(t,y);
title('2ASK demodulated signal');
xlabel('Time');
ylabel('Amplitude');
```
其中,`am`为消息信号频率,`fm`为消息信号幅度,`fc`为载波信号频率,`fs`为采样频率。调制代码中,先生成消息信号和载波信号,然后进行2ASK调制,最后绘制调制信号波形。解调代码中,先将接收到的信号与载波信号相乘,得到包含2ASK调制信号的信号,然后用低通滤波器滤波,得到解调后的信号,最后绘制解调信号波形。
阅读全文