?? bpsk.m
字號:
% BPSK Generates a BPSK carrier wave based on the binary data
% that results from the ADC.
% The algorithm is based on the fact that the sinusoid created
% has one iteration of its phase per data bit of the bin_sequence
% array. The 0s of the bin_sequence are replaced with -1s and
% this array is extended to match the size of the sinusoid array.
% The sinusoid's phase is then shifted by multiplying it with the
% resulting array of 1s and -1s to invert the appropriate cycles
% of the sinusoid.
% Completeed: July 24, 2005
% Terrence Irving
% 2005 NSF REU in SDR
% Stevens Institute of Technology
% Hoboken, NJ USA
% Globalize object handles that this component must access.
global bpsk_pb sssa_base done_text_fontsize bpsk_done_dims adc_pb
% Globalize the appropriate data created by this component.
global sinusoid_data carrier bin_sequence
% Change previous button's color (MATLAB 7 precaution).
set(adc_pb, 'backgroundcolor', 'white');
set(adc_pb, 'foregroundcolor', 'black');
disp('Binary sequence input successfully');
% Binary sequence is located in encoded_data (created by ADC).
bin_sequence = encoded_data;
% Get the length of bin_sequence, or the number of data bits contained
% within the binary sequence.
temp = size(bin_sequence);
total_bits = temp(1)
clear temp;
% Create a time vector for the sinusoid, based on the amount of bits
% in the binary sequence. There should be one period of the sinusoid
% (2*pi) per data bit.
disp('Creating time vector');
t = [0: pi/20: (2*pi)*total_bits];
disp('Time vector created');
% Get the length of the time vector.
temp = size(t);
t_length = temp(1, 2);
clear temp;
% Generate the sinusoid array.
disp('Creating sine vector');
sinusoid_data = sin(t);
disp('Sine vector created');
% Get the length of the sinusoid array.
temp = size(sinusoid_data);
sinusoid_length = temp(1, 2);
clear temp;
% There are 40 data points (array cells) per cycle of the sinusoid. This
% can be calculated from the time vector, t, and visual inspect confirms
% it.
DP_PER_CYCLE = 40;
% Go through original binary sequence, replacing 0s with -1s.
disp('Replacing 0s with -1s in binary sequence');
for k = 1: total_bits
if bin_sequence(k, 1) == 0
bin_sequence(k, 1) = -1;
end
end
disp('0s replaced in binary sequence');
% Create the extended binary sequence array based on the DP_PER_CYCLE
% concept. This array will be the same length as the sinusoid data array,
% and the first data cell will contain a 1 (data point of the first cycle
% is in cell 2, not 1--"nothing" is in the first cell).
disp('Allocating memory for extended binary sequence');
bin_sequence_extended = ones(sinusoid_length, 1);
disp('Memory allocated for extended binary sequence');
disp('Placing a 1 in the first cell of the extended binary sequence array');
bin_sequence_extended(1, 1) = 1; % first cell of sinusoid data is "garbage"
disp('1 placed in the first cell of the extended binary sequence array');
% In the extended binary sequence, each bit is repeated 40 times before
% moving on to the next bit.
extd_start_index = 2; % start repeating bits in cell 2 of extd sequence
disp('Creating extended binary sequence array');
for n = 1: total_bits % move through entire binary seqeunce
extd_stop_index = (DP_PER_CYCLE * n) + 1; % update stop index--stop repeating current bit at 41, 81, 121...
for m = extd_start_index: extd_stop_index
bin_sequence_extended(m, 1) = bin_sequence(n, 1); % place the current bit into the extd seq.
end
extd_start_index = extd_start_index + DP_PER_CYCLE; % start filling with repeated bits again DP_PER_CYCLE cells down the road
end
disp('Extended binary sequence array created');
% Replace -1s with 0s in the binary sequence.
disp('Replacing -1s with 0s in binary sequence');
for k = 1: total_bits
if bin_sequence(k, 1) == -1
bin_sequence(k, 1) = 0;
end
end
disp('-1s replaced in binary sequence');
% Make the extended binary sequence data a row vector.
bin_sequence_extended = bin_sequence_extended';
% Multiply the extended binary sequence with the sinusoid data to generate
% the BPSK carrier signal.
disp('Creating carrier signal');
carrier = bin_sequence_extended.*sinusoid_data;
disp('BPSK carrier signal created');
disp(' '); % blank line
% Free memory.
clear bin_sequence_extended sinusoid_cycle_index;
clear counter cycle i k m n s t_length test w;
clear DP_PER_CYCLE extd_start_index extd_stop_index t sinusoid_length;
% Change button color and update text when component is finished.
set(bpsk_pb, 'backgroundcolor', 'white');
set(bpsk_pb, 'foregroundcolor', 'black');
bpsk_done = uicontrol(sssa_base,...
'style', 'text',...
'fontsize', done_text_fontsize,...
'foregroundcolor', 'white',...
'backgroundcolor', [.5 0 0],... % matches background image color
'horizontalalignment', 'center',...
'string', 'DONE',...
'position', bpsk_done_dims);
% Pause for one second before continuing, giving the button time to update.
pause(1);
% Continue on.
srrc_trans_filter;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -