📄 despread.m
字号:
% DESPREAD De-pread's the received voice signal.
% Because the Walsh Code is a piece of the whole system,
% the Walsh and extended Walsh data will not be created
% again (locally). They will come from what was
% already created and left in the workspace by SPREAD. It
% should be noted that real-world systems are usally
% designed in a way such that all parties generate their
% codes locally.
% Completeed: July 24, 2005
% Terrence Irving
% 2005 NSF REU in SDR
% Stevens Institute of Technology
% Hoboken, NJ USA
% This will use much of the same ideas and code from spread.m,
% as the Walsh Code system is considered to be a mutual component of
% the entire spread spectrum system.
% Globalize object handles that this component must access.
global file help new speakers_pb spkrs_image adc_pb bpsk_pb dac_pb
global debpsk_pb despread_pb speakers_pb spread_pb srrc_1_pb srrc_2_pb
global done_text_fontsize despread_done_dims dac_pb
% Globalize the appropriate data created by this component.
global voice_data_received
% Change previous button's color (MATLAB 7 precaution).
set(dac_pb, 'backgroundcolor', 'white');
set(dac_pb, 'foregroundcolor', 'black');
% De-spread the receieved data (receiver, of course, knows the Walsh Code
% that was used for this transmission).
voice_data_extended_received = voice_data_spread_received.*walsh_extended;
% Allocate voice data array.
voice_data_received = ones(voice_data_extended_length/walsh_factor, 1);
disp('De-spreading signal');
% De-extend the extended received voice data by taking only every
% walsh_factorth piece of extended data to compose the voice data.
index = 1; % index into voice_data_received (manually incremented)
for i = [walsh_factor: walsh_factor: voice_data_extended_length] % take the 4th, 8th, etc, because data is repeated walsh_factor times in extended array
voice_data_received(index, 1) = voice_data_extended_received(i, 1);
index = index + 1; % increment index
end
disp('Original voice data recovered');
% One-second long input signal was sampled at 8 kHz, meaning 8000 samples
% were taken.
total_input_samples = 8000;
disp('Clipping signal amplitude');
% If values of the received signal are greater than 1, clip them.
for i = 1: total_input_samples
if voice_data_received(i, 1) > 1
voice_data_received(i, 1) = 1;
end
end
% Run a separate loop to clip values less than -1.
for i = 1: total_input_samples
if voice_data_received(i, 1) < -1
voice_data_received(i, 1) = -1;
end
end
disp('Signal amplitude clipped');
disp('Received signal de-spread');
disp(' '); % blank line
disp('3SA simulation complete');
% Change button color and update text when component is finished.
set(despread_pb, 'backgroundcolor', 'white');
set(despread_pb, 'foregroundcolor', 'black');
despread_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', despread_done_dims);
% Enable the main window menu items when component is finished running.
set(file, 'enable', 'on');
set(help, 'enable', 'on');
% Enable all pushbuttons except for the microphone when the simulation is
% finished running (forces user to do "File: New") and change status text.
% Also change component pushbuttons' color to white (MATLAB 7 precaution).
set(file, 'enable', 'on');
set(new, 'enable', 'on');
set(help, 'enable', 'on');
set(speakers_pb, 'cdata', spkrs_image);
set(adc_pb, 'enable', 'on');
set(adc_pb, 'backgroundcolor', 'white');
set(adc_pb, 'foregroundcolor', 'black');
set(bpsk_pb, 'enable', 'on');
set(bpsk_pb, 'backgroundcolor', 'white');
set(bpsk_pb, 'foregroundcolor', 'black');
set(dac_pb, 'enable', 'on');
set(dac_pb, 'backgroundcolor', 'white');
set(dac_pb, 'foregroundcolor', 'black');
set(debpsk_pb, 'enable', 'on');
set(debpsk_pb, 'backgroundcolor', 'white');
set(debpsk_pb, 'foregroundcolor', 'black');
set(despread_pb, 'enable', 'on');
set(despread_pb, 'backgroundcolor', 'white');
set(despread_pb, 'foregroundcolor', 'black');
set(speakers_pb, 'enable', 'on');
set(spread_pb, 'enable', 'on');
set(spread_pb, 'backgroundcolor', 'white');
set(spread_pb, 'foregroundcolor', 'black');
set(srrc_1_pb, 'enable', 'on');
set(srrc_1_pb, 'backgroundcolor', 'white');
set(srrc_1_pb, 'foregroundcolor', 'black');
set(srrc_2_pb, 'enable', 'on');
set(srrc_2_pb, 'backgroundcolor', 'white');
set(srrc_2_pb, 'foregroundcolor', 'black');
set(status_txt, 'string', 'Simulation Complete');
% Free memory.
clear i index voice_data_extended_length voice_data_extended_received;
% Return control to spread.
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -