基于matlab的QAM、PSK、ASK、OFDM调制解调代码及波形图
时间: 2023-09-26 18:14:18 浏览: 114
以下是基于MATLAB的QAM、PSK、ASK、OFDM调制解调代码及波形图。
QAM调制解调代码及波形图:
```matlab
clc
clear all
close all
M=16;
k=log2(M);
Fs=1000;
fc=10;
T=1/Fs;
t=T:T:1;
N=length(t);
message=randi([0 M-1],1,N*k);
message_matrix=reshape(message,N,k);
decimal=zeros(1,N);
for i=1:N
decimal(i)=bi2de(message_matrix(i,:));
end
qam_symbols=qammod(decimal,M);
qam_signal=qam_symbols.*exp(j*2*pi*fc*t);
noise=0.1*(randn(1,length(qam_signal))+j*randn(1,length(qam_signal)));
received_signal=qam_signal+noise;
demod_qam=received_signal.*exp(-j*2*pi*fc*t);
demod_qam_symbols=qamdemod(demod_qam,M);
demod_decimal=reshape(de2bi(demod_qam_symbols,k),1,N*k);
error_rate=sum(xor(demod_decimal,message))/length(message);
scatterplot(qam_symbols);
title('QAM调制波形图');
figure;
scatterplot(demod_qam_symbols);
title('QAM解调波形图');
```
PSK调制解调代码及波形图:
```matlab
clc
clear all
close all
M=16;
k=log2(M);
Fs=1000;
fc=10;
T=1/Fs;
t=T:T:1;
N=length(t);
message=randi([0 M-1],1,N*k);
message_matrix=reshape(message,N,k);
decimal=zeros(1,N);
for i=1:N
decimal(i)=bi2de(message_matrix(i,:));
end
psk_symbols=pskmod(decimal,M);
psk_signal=psk_symbols.*exp(j*2*pi*fc*t);
noise=0.1*(randn(1,length(psk_signal))+j*randn(1,length(psk_signal)));
received_signal=psk_signal+noise;
demod_psk=received_signal.*exp(-j*2*pi*fc*t);
demod_psk_symbols=pskdemod(demod_psk,M);
demod_decimal=reshape(de2bi(demod_psk_symbols,k),1,N*k);
error_rate=sum(xor(demod_decimal,message))/length(message);
scatterplot(psk_symbols);
title('PSK调制波形图');
figure;
scatterplot(demod_psk_symbols);
title('PSK解调波形图');
```
ASK调制解调代码及波形图:
```matlab
clc
clear all
close all
M=16;
k=log2(M);
Fs=1000;
fc=10;
T=1/Fs;
t=T:T:1;
N=length(t);
message=randi([0 M-1],1,N*k);
message_matrix=reshape(message,N,k);
decimal=zeros(1,N);
for i=1:N
decimal(i)=bi2de(message_matrix(i,:));
end
ask_symbols=ammod(decimal,fc,Fs);
ask_signal=ask_symbols.*exp(j*2*pi*fc*t);
noise=0.1*(randn(1,length(ask_signal))+j*randn(1,length(ask_signal)));
received_signal=ask_signal+noise;
demod_ask=amdemod(received_signal,fc,Fs);
demod_decimal=reshape(de2bi(demod_ask,k),1,N*k);
error_rate=sum(xor(demod_decimal,message))/length(message);
plot(t,ask_signal);
title('ASK调制波形图');
figure;
plot(t,demod_ask);
title('ASK解调波形图');
```
OFDM调制解调代码及波形图:
```matlab
clc
clear all
close all
M=16;
k=log2(M);
n=8; % 子载波数量
cp=3; % 循环前缀长度
Fs=1000;
fc=10;
T=1/Fs;
t=T:T:1;
N=length(t);
message=randi([0 M-1],1,n*k);
message_matrix=reshape(message,n,k);
decimal=zeros(n,1);
for i=1:n
decimal(i)=bi2de(message_matrix(i,:));
end
ofdm_symbols=ifft(decimal);
ofdm_signal=zeros(1,N);
for i=1:n
ofdm_signal((i-1)*(N/n)+1:i*(N/n))=ofdm_symbols(i);
end
ofdm_signal=[ofdm_signal(end-cp*N/n+1:end) ofdm_signal];
ofdm_signal=[ofdm_signal ofdm_signal(1:cp*N/n)];
noise=0.1*(randn(1,length(ofdm_signal))+j*randn(1,length(ofdm_signal)));
received_signal=ofdm_signal+noise;
rx_ofdm_signal=received_signal(cp*N/n+1:end-cp*N/n);
rx_ofdm_symbols=zeros(n,1);
for i=1:n
rx_ofdm_symbols(i)=rx_ofdm_signal((i-1)*(N/n)+1:i*(N/n));
end
demod_decimal=zeros(n,k);
for i=1:n
demod_decimal(i,:)=de2bi(round(abs(rx_ofdm_symbols(i))));
end
demod_decimal=reshape(demod_decimal',1,n*k);
error_rate=sum(xor(demod_decimal,message))/length(message);
plot(t,ofdm_signal);
title('OFDM调制波形图');
figure;
plot(t(cp*N/n+1:end-cp*N/n),rx_ofdm_signal);
title('OFDM解调波形图');
```
阅读全文