📄 ofdm2.m
字号:
信道幅频响应
%Design filter by specifying delay in units and
%looking at mag and phase response
% Good default values for fft size=128 and num_carriers=32
delay_1=6; % 6
attenuation_1=0.35; % 0.35
delay_2=10; % 10
attenuation_2=0.30; % 0.30
num=[1,zeros(1,delay_1-1), attenuation_1,zeros(1,delay_2-delay_l-1),
attenuation_2];
[H, W]=freqz(num,l,512);%computefr equencyr esponse
mag=20*log10(abs(H)); %magnitude in dB
phase=angle(H)*180/pi; %phase angle in degrees
figure(9),clf
subplot(211),plot(W/(2*pi),mag)
title('Magnitude response of multipath channel')
xlabel('Digital Frequency'),ylabel('Magnitude in dB')
subplot(212),plot(W/(2*pi),phase)
title('Phase response of multipath channel')
xlabel('Digital Frequency'), ylabel('Phase in Degrees')
break
对比OFDM与16-QAM的传输性能
%Analysis
disp(''), disp('------------------------')
disp('Preparing Analysis')
figure(2),clf
if(input_type==1)&(test_input_type==1)
subplot(221),stem(datai n),title('OFDM二进制输入数据')
subplot(223),stem(output),title('OFDM二进制恢复数据')
else
subplot(221),plot(data_samples),title('OFDM 输入信号');
subplot(223),plot(output_samples),title('OFDM恢复信号');
end
subplot(222),plot(xmit),title('OFDM发射');
subplot(224),plot(recv),title('OFDM接收');
dig_x_axis=(1:length(QAM_tx_data))/length(QAM_tx_ data);
figure(4 ),clf,subplot(212)
freq_data=abs(fft(QAM_rx_data));
L=length(freq_data)/2;
dig_x_axis=(l:length(xmit))/length(xmit);
figure(3),clf
if channel_on== 1
num=[1,zeros(1,d1-1),al ,zeros(1,d2-dl-1),a2 ];
den=[1];
[H,w]=freqz(num,den,512);
mag=20*log10(abs(H));
phase=angle(H)*180/pi;
subplot(313)
freq_data=abs(fft(recv));
L=length(freq_data)/2;
plot(dig_x_axis(1:L),freq_data(1:L))
xlabel('OFDM接收端FFT')
axis_temp=axis;
subplot(311),
freq_data=abs(fft(xmit));
plot(dig_x_axis(1:L),freq_data(I:L)),axis(axis_temp)
title('OFDM发射端FFT')
subplot( 312)
plot(W /( 2*pi),mag),
ylabel('信道幅度响应')
else
subplot( 212)
freq_data=abs(ft(recv));
L=length(freq_data)/2;
plot(dig_x_axis(1:L),freq_data(1:L))
xlabel ('OFDM接收端FFT')
axis_temp=axis;
subplot( 211),
freq_data=abs(fFt(xmit));
plot(dig_x_ axis(1:L),freq_data(1:L)),axis(axis_temp)
title ('OFDM发射端FFT')
end
if file_input_type==4
figure(5 )
subplot( 211)
image(data_in);
colormap(map);
subplot( 212)
image(output);
colormap(map);
end
if do_QAM==1 %analyze if QAM was done
figure(4),clf
if( input_type==1)&(test_input_type==1)
subplot( 221),stem(data_in),title('QAM Binary Input Data');
subplot( 223),stem(QAM_sdata_out),title('QAM Recovered Binary Data')
else
subplot(221),plot(data_samples),title('QAM 输入信号');
subplot(223),plot(QAM_output_samples),title('QAM 恢复信');
end
subplot(222),plot(QAM_tx_data),title('发射端QAM');
subplot(224),plot(QAM_rx_data),title('接收端QAM');
dig_x_axis=(l:length(QAM_tx_data))/length(QAM_tx_data);
figure(5),clf
if channel_on ==1
subplot(313)
freq_data=abs(fft(QAM_rx_data));
L=length(freq-data)/2;
plot(dig_x_axis(1:L),freq_data(1:1));
xlabel('QAM接收端FFT')
axi_temp=axis;
subplot(311),
freq _data=abs(fft(QAM_tx_data));
plot(dig_x_axis(1:L),freq_data(1:L)),axis(axis_temp)
title('QAM发射端FFT')
subplot(312)
plot(W/(2*pi),mag)
ylabel('信道幅度响应')
else
subplot(212)
freq _data=abs(fft(QAM_rx_data));
L=length(freq_data)/2;
plot(dig_x_axis(1:L),freq_data(l:L))
title('QAM接收端FFT')
axis_temp=axis;
subplot(211),
freq_data=abs(fft(QAM_tx_data));
plot(dig_x_axis(1:L),freq_data(1:L)),axis(axis_temp)
title('QAM 发射端FFT')
end
%Plots the QAM Received Signal Constellation
figure(6),clf,pl ot(xxx,yyy,'ro'),grid on,axis([-2.5 2.5 -2.5 2.5]),hold on
%Overlay plot of transmitted constellation
x_ const=[-1.5 -0.5 0.5 1.5 -1.5 -0.5 0.5 1.5 -1.5 -0.5 0.5 1.5 -1.5 -0.5 0.5 1.5];
y_const=[-1.5 -1.5 -1.5 -1.5 -0.5 -0.5 -0.5 -0.5 0.5 0.5 0.5 0.5 1.5 1.5 1.5 1.5];
plot(x_const,y c onst,'b*')
%Overlay of constellation boundarys
x1=[-2 -2];x2 =[-1 -1];x3 =[0 0];x4=[1 1];x5 =[2 2];x6=[-2 2];
yl=[-2 -2];y2 =[-1 -1];y3 =[0 0];y4=[1 I];y5 =[2 2];y6=[-2 2];
plot(xl,y6),plot(x2,y6),plot(x3,y6),plot(x4,y6),plot(x5,y6)
plot(x6,yl),plot(x6,y2),plot(x6,y3),plot(x6,y4),plot(x6,y5)
hold off
title('l6-QAM接收到的信号集群和判决边界')
binary_err_bits_ QAM=0;
for i=1:length(data_in)
err= abs(data_in(i)-QAM_data_out(i));
if err> 0
binary_err_bits_QAM=binary_err_bits_QAM+1;
end
end
BER_QAM=100*binary_err_bits_QAM/data_length;
end
figure(7),clf
if channelon==1
subplot(211),plot(W/(2*pi),mag),title('信幅度响应')
xlabel('数字频率'),ylabel('幅度dB')
subplot(212),plot(W/(2*pi),phase),title('信道相位响应')
xlabel('数字频率'),ylabel('相位度数')
else
title('Channel is turned off-No frequency responseto plot')
end
%Compare output to input and count errors
binary_err_bits_OFDM=0;
for i=1:length(data_in)
err=abs(data_in(i)-output(i));
if err>0
binary_err_bits_OFDM=binary_err_bits_OFDM+1;
end
end
BER_OFDM=100*binary_err_bits_OFDM/data_length;
disp(strcat('OFDM:BER=',num2str(BER_OFDM,3),'%'))
disp(strcat('Number of error bits=',num2str(binary_err_bits_OFDM)))
if (do_QAM==1)
disp(strcat('QAM: BER=',num2str(BER_QAM,3),'%'))
disp(strcat(' Number of error bits=',num2str(binary_err_bits_QAM)))
end
%Display text file before and after modulation
if (input_type==2)&(file_input_type==2)
original_text_file=char(data_samples')
if do_QAM==I
edit QAM_text_out.txt
end
edit OFDM_text_out.txt
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -