📄 dac.m
字号:
% DAC Performs digital to analog conversion (DAC) on the received
% binary sequence, including signal expansion with a Mu-law
% compander.
% 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 dac_pb sssa_base done_text_fontsize dac_done_dims debpsk_pb
% Globalize the appropriate data created by this component.
global voice_data_spread_received
% Change previous button's color (MATLAB 7 precaution).
set(debpsk_pb, 'backgroundcolor', 'white');
set(debpsk_pb, 'foregroundcolor', 'black');
% Redundant but clear--bits expected turned out to be bits received.
total_bits_received = total_bits_expected;
% Bits needed to represent transmitted quantized data (can be assumed that
% the receiver knows this information).
BITS_NEEDED = 4;
% Convert the binary sequence into an array of quantized integers.
% The current BITS_NEEDED (four) bits will be stored in current_bin_word for
% clarity. Then that row vector will be converted to a string, then that
% string will be converted to an integer value and stored in the received
% quantized data array (quantized_data_received).
% Binary to string to integer example:
% >> a = 0; b = 1;
% >> c = 1; d = 1;
% >> test = [num2str(a) num2str(b) num2str(c) num2str(d)];
% >> test
% test = 0111
% >> bin2dec(test)
% ans = 7
disp('Creating received quantized data array');
quantized_data_received = ones((total_bits_received - qd_rows) / BITS_NEEDED, 1); % the quantized data itself does not include the polarity data
current_int_start = 1; % starting bit index for current integer (first time it's 1)
current_int_end = BITS_NEEDED; % ending bit index for current integer (first time it's 4)
for j = 1: (total_bits_received -qd_rows) / BITS_NEEDED % as above--stop when the last piece of quantized data has been worked on
current_bin_word_ints = bin_sequence_received(current_int_start: current_int_end, 1)'; % bits for current integer
current_bin_word_str = [num2str(current_bin_word_ints(1, 1)) num2str(current_bin_word_ints(1, 2)) num2str(current_bin_word_ints(1, 3)) num2str(current_bin_word_ints(1, 4))]; % make string
quantized_data_received(j, 1) = bin2dec(num2str(current_bin_word_str)); % convert the bin word to a string then convert that string to an int
current_int_start = current_int_start + BITS_NEEDED; % move BITS_NEEDED cells down to get next start index
current_int_end = current_int_end + BITS_NEEDED; % move BITS_NEEDED cells down to get next end index
end
% Now acquire the polarity information from bin_sequence_received (again, it makes
% up the last 16000 data points of bin_sequence_received).
disp('Acquiring quantized data polarity information')
polarity_array_received = bin_sequence_received((BITS_NEEDED*qd_rows)+1: total_bits_received, :);
% Change polarity_array_received 0s to -1s.
for i = 1: qd_rows
if polarity_array_received(i, 1) == 0
polarity_array_received(i, 1) = -1;
end
end
disp('Quantized data polarity information acquired');
% Use polarity_array_received to negate those quantized_data_received
% values that are supposed to be negative.
disp('Negating appropriate quantized data values');
quantized_data_received = quantized_data_received .* polarity_array_received;
disp('Appropriate quantized data values negated');
% Expand the recovered quantized data.
disp('Recovering spread voice data');
quantized_data_rec_denormalized = quantized_data_received/INT_FACTOR; % denormalize quantized data (ie go back to floating point values)
V2 = max(quantized_data_rec_denormalized); % get maximum value of denormalized quantized data
voice_data_spread_received = compand(quantized_data_rec_denormalized, MU, V2, 'mu/expander'); % expand data, resulting in spread voice data
disp('Spread voice data recovered');
disp(' '); % blank line
% Free memory.
clear total_bits_expected BITS_NEEDED INT_FACTOR MU V2 current_bin_word_str current_bin_word_ints;
clear current_int_end current_int_start i j polarity_array_received qd_rows;
% Change button color and update text when component is finished.
set(dac_pb, 'backgroundcolor', 'white');
set(dac_pb, 'foregroundcolor', 'black');
dac_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', dac_done_dims);
% Pause for one second before continuing, giving the button time to update.
pause(1);
% Continue on.
despread;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -