forked from MeowLucian/SDR_Matlab_OFDM_802.11a
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHardware_RX.m
74 lines (63 loc) · 2.58 KB
/
Hardware_RX.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
clear;close all;clc;j=1i;
%% Button setting
button = uicontrol; % 產生按鈕
set(button,'String','Stop!','Position',[1300 20 100 60]); % 加入文字「Stop!」
%% Parameter
rx_object = sdrrx('ZedBoard and FMCOMMS2/3/4',...
'IPAddress','192.168.30.3',...
'CenterFrequency',2.4e9,...
'BasebandSampleRate', 20e6,...
'ChannelMapping', 1,...
'SamplesPerFrame', 3000);
Ready_Time=200;
scale=1024;
%% Main
state=1; % 開始狀態
Run_time_number=1;
while(state==1)
try
tic
[data_rx_raw, dataLength, lostSample] = step(rx_object);
if Run_time_number>Ready_Time
% ----- RX Raw -----%
data_rx=double(data_rx_raw)./scale; % [3000x1]
RX_real=real(data_rx)';
RX_imag=imag(data_rx)';
RX=RX_real+RX_imag*j; % [1x3000]
drawnow;
subplot(2,4,1),plot(RX,'.');title('RX-Raw');axis([-1.5 1.5 -1.5 1.5]);axis square;
% ----- Demodulation -----%
[Threshold,M_n,Threshold_graph,H_est_time,RX_Payload_1_no_Equalizer,RX_Payload_2_no_Equalizer,RX_Payload_1_no_pilot,RX_Payload_2_no_pilot,BER]=OFDM_RX(RX);
subplot(2,4,1),plot(RX,'.');title('RX-Raw');axis([-1.5 1.5 -1.5 1.5]);axis square;
subplot(2,4,2),plot(1:length(M_n),M_n,1:length(M_n),Threshold_graph);title('Packet Detection');axis([1,length(M_n),0,1.2]);axis square;
subplot(2,4,3),plot(abs(H_est_time));title('Channel Estimation');axis([1 64 0 7]);axis square;
subplot(2,4,4),plot(RX_Payload_1_no_Equalizer,'*');
hold on
subplot(2,4,4),plot(RX_Payload_2_no_Equalizer,'*');title('Before Equalizer');axis([-8 8 -8 8]);axis square;
hold off
subplot(2,4,5),plot(RX_Payload_1_no_pilot,'*');
hold on
subplot(2,4,5),plot(RX_Payload_2_no_pilot,'*');title({'Demodulation';['BER = ',num2str(BER)]});axis([-1.5 1.5 -1.5 1.5]);axis square;
hold off
set(gcf,'Units','centimeters','position',[1 2 49 24]);
Run_time_number=Run_time_number+1;
end % Start
if Run_time_number<=Ready_Time % Ready
% disp('Ready');
end
Run_time_number=Run_time_number+1;
% ----- Button Behavior -----%
set(button,'Callback','setstate0'); % 設定按鈕的反應指令
set(gcf,'Units','centimeters','position',[1 2 49 24]);
catch
ErrorMessage=lasterr;
fprintf('Error Message : \n');
disp(ErrorMessage);
fprintf(2,'Error occurred & Stop Hardware\n');
% release(rx_object);
% state=0;
end % Error control
end % While
release(rx_object);
close all;
disp('Software Complete');