写出2ASK、2PSK、2DPSK、2FSK四种调制方式的matlab代码
时间: 2023-06-24 22:09:16 浏览: 165
1. 2ASK(Amplitude Shift Keying)调制方式的matlab代码:
```matlab
% 2ASK调制
clear; clc;
fc = 100; %载波频率
fs = 1000; %采样频率
T = 1/fs; %采样周期
t = 0:T:1; %采样时间
Ac = 1; %载波振幅
fc1 = 10; %信号频率
fc2 = 20; %信号频率
As1 = 2; %信号1振幅
As2 = 4; %信号2振幅
s1 = As1*sin(2*pi*fc1*t); %信号1
s2 = As2*sin(2*pi*fc2*t); %信号2
s = s1 + s2; %叠加信号
figure(1)
subplot(311)
plot(t, s1), grid on;
title('信号1');
subplot(312)
plot(t, s2), grid on;
title('信号2');
subplot(313)
plot(t, s), grid on;
title('叠加信号');
xlabel('t/s');
ylabel('幅值');
% 2ASK调制
for ii=1:length(t)
if s(ii) > 0
m(ii) = 1;
else
m(ii) = 0;
end
end
% 2ASK解调
for ii=1:length(t)
if m(ii) == 1
M(ii) = Ac*s(ii);
else
M(ii) = 0;
end
end
figure(2)
subplot(211)
plot(t, s), grid on;
title('调制信号');
subplot(212)
plot(t, M), grid on;
title('解调信号');
xlabel('t/s');
ylabel('幅值');
```
2. 2PSK(Phase Shift Keying)调制方式的matlab代码:
```matlab
% 2PSK调制
clear; clc;
fc = 100; %载波频率
fs = 1000; %采样频率
T = 1/fs; %采样周期
t = 0:T:1; %采样时间
Ac = 1; %载波振幅
fc1 = 10; %信号频率
fc2 = 20; %信号频率
As1 = 2; %信号1振幅
As2 = 4; %信号2振幅
s1 = As1*sin(2*pi*fc1*t); %信号1
s2 = As2*sin(2*pi*fc2*t); %信号2
s = s1 + s2; %叠加信号
figure(1)
subplot(311)
plot(t, s1), grid on;
title('信号1');
subplot(312)
plot(t, s2), grid on;
title('信号2');
subplot(313)
plot(t, s), grid on;
title('叠加信号');
xlabel('t/s');
ylabel('幅值');
% 2PSK调制
for ii=1:length(t)
if s(ii) > 0
m(ii) = 1;
else
m(ii) = -1;
end
end
% 2PSK解调
for ii=1:length(t)
if m(ii) == 1
M(ii) = Ac*sin(2*pi*fc*t(ii));
else
M(ii) = Ac*sin(2*pi*fc*t(ii)+pi);
end
end
figure(2)
subplot(211)
plot(t, s), grid on;
title('调制信号');
subplot(212)
plot(t, M), grid on;
title('解调信号');
xlabel('t/s');
ylabel('幅值');
```
3. 2DPSK(Differential Phase Shift Keying)调制方式的matlab代码:
```matlab
% 2DPSK调制
clear; clc;
fc = 100; %载波频率
fs = 1000; %采样频率
T = 1/fs; %采样周期
t = 0:T:1; %采样时间
Ac = 1; %载波振幅
fc1 = 10; %信号频率
fc2 = 20; %信号频率
As1 = 2; %信号1振幅
As2 = 4; %信号2振幅
s1 = As1*sin(2*pi*fc1*t); %信号1
s2 = As2*sin(2*pi*fc2*t); %信号2
s = s1 + s2; %叠加信号
figure(1)
subplot(311)
plot(t, s1), grid on;
title('信号1');
subplot(312)
plot(t, s2), grid on;
title('信号2');
subplot(313)
plot(t, s), grid on;
title('叠加信号');
xlabel('t/s');
ylabel('幅值');
% 2DPSK调制
for ii=1:length(t)
if ii == 1
m(ii) = 1;
else
if s(ii) > 0
m(ii) = m(ii-1);
else
m(ii) = -m(ii-1);
end
end
end
% 2DPSK解调
for ii=1:length(t)
if ii == 1
M(ii) = Ac*sin(2*pi*fc*t(ii));
else
if m(ii) == m(ii-1)
M(ii) = M(ii-1);
else
M(ii) = Ac*sin(2*pi*fc*t(ii)+pi);
end
end
end
figure(2)
subplot(211)
plot(t, s), grid on;
title('调制信号');
subplot(212)
plot(t, M), grid on;
title('解调信号');
xlabel('t/s');
ylabel('幅值');
```
4. 2FSK(Frequency Shift Keying)调制方式的matlab代码:
```matlab
% 2FSK调制
clear; clc;
fc = 100; %载波频率
fs = 1000; %采样频率
T = 1/fs; %采样周期
t = 0:T:1; %采样时间
Ac = 1; %载波振幅
fc1 = 10; %信号频率
fc2 = 20; %信号频率
As1 = 2; %信号1振幅
As2 = 4; %信号2振幅
s1 = As1*sin(2*pi*fc1*t); %信号1
s2 = As2*sin(2*pi*fc2*t); %信号2
s = s1 + s2; %叠加信号
figure(1)
subplot(311)
plot(t, s1), grid on;
title('信号1');
subplot(312)
plot(t, s2), grid on;
title('信号2');
subplot(313)
plot(t, s), grid on;
title('叠加信号');
xlabel('t/s');
ylabel('幅值');
% 2FSK调制
for ii=1:length(t)
if s(ii) > 0
m(ii) = sin(2*pi*fc1*t(ii));
else
m(ii) = sin(2*pi*fc2*t(ii));
end
end
% 2FSK解调
[b,a] = butter(4,2*fc/fs);
m_filt = filter(b,a,m);
N = length(m_filt);
for ii=1:N
if m_filt(ii) > 0
M(ii) = 1;
else
M(ii) = 0;
end
end
figure(2)
subplot(211)
plot(t, s), grid on;
title('调制信号');
subplot(212)
plot(t, M), grid on;
title('解调信号');
xlabel('t/s');
ylabel('幅值');
```
阅读全文