📄 spread.m
字号:
% SPREAD Spread's the voice signal by injecting a Walsh Code.
% This function generates a Hadamard matrix of the
% appropriate size and then randomly selects a row of that
% matrix, which results in a Walsh Code. It then extends
% and spreads the input signal.
% Completeed: July 24, 2005
% Terrence Irving
% 2005 NSF REU in SDR
% Stevens Institute of Technology
% Hoboken, NJ USA
function [] = spread(command, spreading_factor)
% Globalize data needed by this component.
global voice_data done_text_fontsize spread_done_dims
% Globalize the appropriate data created by this part of the component.
global voice_data_spread walsh walsh_factor spread_input_player
% Globalize object handles that this component must access.
global adc_pb bpsk_pb dac_pb debpsk_pb despread_pb file help sssa_base
global mic_image mic_disabled_image mic_pb speakers_pb spkrs_image
global spkrs_disabled_image spread_pb srrc_1_pb srrc_2_pb status_txt
% If the full simulation is running, disable the main window menu items,
% disable all pushbuttons, and change status text when component begins
% running.
if strcmp(command, 'full_spread')
set(file, 'enable', 'off');
set(help, 'enable', 'off');
set(mic_pb, 'cdata', mic_disabled_image);
set(speakers_pb, 'cdata', spkrs_disabled_image);
set(adc_pb, 'enable', 'off');
set(bpsk_pb, 'enable', 'off');
set(dac_pb, 'enable', 'off');
set(debpsk_pb, 'enable', 'off');
set(despread_pb, 'enable', 'off');
set(mic_pb, 'enable', 'off');
set(speakers_pb, 'enable', 'off');
set(spread_pb, 'enable', 'off');
set(srrc_1_pb, 'enable', 'off');
set(srrc_2_pb, 'enable', 'off');
set(status_txt, 'string', 'Running...');
end
% Generate the corresponding Hadamard matrix.
matrix = hadamard(spreading_factor);
% Generate a random row index into matrix.
index = randint(1, 1, [1, spreading_factor]);
% Select the Walsh Code.
walsh = matrix(index, :);
% the Walsh Code's length is equal to spreading_factor.
walsh_factor = spreading_factor;
% Transform the walsh row vector into a column vector.
walsh = walsh';
% Store the number of rows in voice_data.
temp = size(voice_data);
voice_data_rows = temp(1);
% Create a matrix to hold the walsh_factor-extended voice data. This
% matrix will have walsh_factor*voice_data_rows number of rows (walsh_factor
% number of voice_extended data bits correspond to one voice data bit).
% The extended array will have one column, just as voice_data does.
voice_data_extended_length = walsh_factor*voice_data_rows;
voice_data_extended = ones(voice_data_extended_length, 1);
% Fill the voice_extended matrix with the voice data, according to the
% walsh_factor. The counter starts at 1 and is incremented by walsh_factor
% each time the row index into voice (j) is incremented. It (counter)
% determines the starting row of voice_extended each time the voice row
% changes. The product walsh_factor*j determines the last row in
% voice_extended to be filled before the voice row index is incremented.
counter = 1;
for j = 1: voice_data_rows
for i = counter: walsh_factor*j
voice_data_extended(i, 1) = voice_data(j, 1);
end
counter = counter+walsh_factor;
end
% Create a temporary matrix to aid in the duplication of the walsh column
% vector into a two-column matrix.
temp = ones(walsh_factor, 1);
% temp's dimensions now match those of what walsh will become, but temp
% contains nothing but 1's. Fill both columns with walsh's data. The
% result will be a two column matrix, each column holding the data found
% in walsh's single column.
for k = 1: walsh_factor
temp(k, 1) = walsh(k);
end
% temp has done its job, so transfer its data to walsh.
walsh = temp;
% Number of times original walsh matrix will be repeated to construct the
% walsh_extended matrix.
repetitions = voice_data_rows;
% Extend the walsh matrix to construct walsh_extended. This will be done
% so that the Walsh Code can be applied to each corresponding voice data bit.
% walsh_extended will be filled one walsh element at a time.
walsh_extended = ones(size(voice_data_extended, 1), 1);
for n = 1: walsh_factor
for m = 0: repetitions - 1
walsh_extended(n + (m*walsh_factor), 1) = walsh(n, 1);
end
end
% By this point the voice and walsh matrices have both been extended and
% contain the same number of elements. Now the Walsh Code can be applied
% to the oversampled voice data. This is the spreading portion of the
% algorithm.
voice_data_spread = voice_data_extended.*walsh_extended;
% Free memory.
clear counter i j k m n;
clear voice_data_rows matrix index temp spreading_factor;
clear walsh_dim voice_data_extended repetitions;
disp('Input signal spread')
disp(' '); % blank line
% Change button color and update text when component is finished.
set(spread_pb, 'backgroundcolor', 'white');
set(spread_pb, 'foregroundcolor', 'black');
spread_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', spread_done_dims);
% Pause for one second before continuing, giving the button time to update.
pause(1);
% Create the spread input audioplayer object.
spread_input_player = audioplayer(voice_data_spread, 8000);
% If this call was for the full simulation, continue on to the next component
% and then return. Otherwise, just return.
if strcmp(command, 'full_spread')
adc;
return;
else
return;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -