📄 component_window_launcher.m
字号:
spkrs_instructions_fontsize = 9;
spkrs_instructions_dims = [.05 .17 .9 .15];
spkrs_outro_fontsize = 13;
spkrs_outro_dims = [.05 .15 .9 .1];
% Set axes dimensions and positions.
mic_axes_dims = [.2 .555 .6 .4];
spread_axes_1_dims = [.15 .75 .7 .2];
spread_axes_2_dims = [.15 .42 .7 .2];
bpsk_axes_1_dims = [.15 .75 .7 .2];
bpsk_axes_2_dims = [.15 .45 .7 .2];
srrc_1_axes_1_dims = [.15 .7 .7 .2];
srrc_1_axes_2_dims = [.15 .35 .7 .2];
srrc_2_axes_1 = [.15 .65 .7 .25];
srrc_2_axes_2 = [.15 .25 .7 .25];
debpsk_axes_1 = [.15 .75 .7 .15];
debpsk_axes_2 = [.15 .5 .7 .15];
debpsk_axes_3 = [.15 .25 .7 .15];
despread_axes_1 = [.15 .67 .7 .22];
despread_axes_2 = [.15 .3 .7 .22];
speakers_axes_1_dims = [.15 .75 .7 .2];
speakers_axes_2_dims = [.15 .425 .7 .2];
otherwise
disp('instructions');
return;
end
%---------------------------------DIMENSIONS---------------------------------%
%-----------------------------UI/CALLBACK STRINGS----------------------------%
% MICROPHONE component window text
microphone_string = ['Click Record to record a new signal to run through the ',...
'simulation. You will have ONE SECOND to make your VOICE recording, ',...
'so it is suggested that you say your name or make some other one or ',...
'two word statement (your timing may take some practice, but you should ',...
'try to begin speaking as soon as you click Record). Click Open to ',...
'select your own saved voice .wav file, or you may use the sample provided ',...
'(DEMO.WAV). Please note that if your selected recording is longer than ',...
'one second, only the first second of data will be loaded and used by 3SA. ',...
'The time domain waveform of your input signal will appear on ',...
'the axes provided. You can click the Hear button to listen to your ',...
'selected input, and you may re-record or open different files as many ',...
'times as you need to. Click the Continue button to begin the full simulation.'];
% SPREAD component window text
spread_string = ['SPREADING is the operation from which direct sequence ',...
'spread spectrum gets its name. Many real-world DSSS systems (such as ',...
'some CDMA cellular telephone networks) use Walsh Codes to spread signals, ',...
'and these are what 3SA uses as well. Spreading with Walsh Codes works ',...
'by first selecting a spreading factor, or Walsh Code length. This value ',...
'is always an integer that results from 2^n, where n is an integer greater ',...
'than or equal to 1 (2^0 = 1 is a valid spreading factor, but the Walsh Code that results ',...
'is 1, and, therefore, no spreading takes place with this specific code). ',...
'The spreading factor (which will be referred to as w for this discussion) is used to generate a ',...
'Hadamard Matrix, which is a w by w matrix of 1s and 0s whose rows are ',...
'orthogonal (two rows are orthogonal if their inner product equals ',...
'0). The rows of the generated Matrix are individual Walsh Codes of length ',...
'w (there is usually a conversion, such as replacing the Code''s 0s with ',...
'1s and its 1s with -1s, so that the voice data is not erased by the Code''s ',...
'0s). The voice data and Walsh codes are then extended by the spreading ',...
'factor and the two are then multiplied together. For example, if your ',...
'input voice signal consisted of 10 data samples and you were spreading it ',...
'with a Walsh Code of length 8, then the voice signal would be extended to ',...
'a length of 80 (each of the 10 data samples would be repeated 8 times), as ',...
'would the Walsh Code''s sequence of 1s and -1s (each bit, or binary digit, of ',...
'the Walsh Code would be repeated 10 times). So, the first 8 data samples of ',...
'the extended voice input signal would be the same--the first data sample ',...
'of the original. This extension of data is the spreading, and the transmitter ',...
'and receiver in a DSSS system are able to generate the same Codes so that ',...
'transmitted signals appear noiselike to spectrum outsiders (because ',...
'outsiders do not possess the correct Code). Real-world Walsh Codes are ',...
'sometimes in the neighborhood of 256 bits. This, joined with the other ',...
'characteristics of spread spectrum communications, makes interception and ',...
'violation of transmitted signals very difficult. You can use the tools in the ',...
'window below this one to generate valid Walsh ',...
'Codes and hear the effects of spreading on your input signal (3SA uses a ',...
'2-bit Walsh Code for memory/processing power reasons--most PCs wouldn''t be able ',...
'to handle too high of a spreading factor when running the entire simulation).'];
% ADC component window text block #1
adc_string_1 = ['ANALOG to DIGITAL CONVERSION is the process by which the input signal''s ',...
'data is converted from an analog signal (which you saw a visual time-domain ',...
'representation of in the previous component''s window) to a binary sequence. ',...
'3SA''s ADC first compresses your input using the Mu-law compression algorithm. ',...
'Mu-law is a North American and Japanese telecommunications compression standard ',...
'that takes advantage of the fact that perceived loudness is generally logarithmic ',...
'(Mu-law is comparable to the European compression standard, which is known as A-law--',...
'the mathematics behind the two are very similar, but the unitless values of constants ',...
'Mu and A are very different). 3SA actually uses a Mu-law compander (compressor/',...
'expander) to compress your input voice data before it is quantized. The ',...
'quantization process groups or organizes your compressed input data (which is ',...
'composed of floating point values) according to a codebook of integers, which is ',...
'determined by a normalized version of the compressed data. These integer values are then made positive, and ',...
'the ADC keeps track of which values were originally negative (the decimal to ',...
'binary conversion was done this way for simplicity). The polarity ',...
'information is then appended onto the end of the binary sequence before moving on. ',...
'The math/flow information below explains how 3SA determines the total number of bits ',...
'needed to represent your input signal.'];
% ADC component window math text
adc_math_string = ['8000 voice data samples * 2-bit Walsh Code = 16,000 samples into the ADC ',...
'--> 16,000 compressed samples --> 16,000 normalized compressed samples --> 16,000 ',...
'quantized values * 4 bits needed to represent each quantized value + ',...
'16,000 pieces of polarity data (1s and -1s) = 80,000 total bits of information'];
% ADC component window text block #2
adc_string_2 = ['As you can see, determining the total number of bits is an intuitive process ',...
'that requires nothing more than keeping track of the accumulation and conversion of the ',...
'input data.'];
% BPSK component window text
bpsk_string = ['BINARY PHASE SHIFT KEYING is a communications modulation (the "placing" of data on a ',...
'carrier signal for transmission) technique. 3SA uses a plain sinusoid as its carrier. ',...
'At this point in the simulation, your input signal is represented by binary data. ',...
'In order to represent the binary data using a sinusoid, changes in the sinusoid''s phase ',...
'will be used, and because there are two different pieces of information to represent with ',...
'the sinusoid (either a 1 or 0), the sinusoid''s phase will have to bounce back and forth ',...
'between 0 and 180 degrees. BPSK can be compared with QPSK (where the base of the Q is ',...
'"quad," or "four"), which uses four phase shifts to represent data. If you don''t ',...
'notice many phase changes on the plot, try re-recording your input, making sure to ',...
'place data in the first sample of the recording (a lack of phase changes may indicate ',...
'that early recording samples are "empty," or 0--then the BPSK would convey only binary 0s).'];
% SRRC #1 component window text
srrc_1_string = ['This SQUARE ROOT RAISED COSINE FILTER is the last component of the transmission ',...
'chain and is the first of two such filters in cascade (the second is the first component of ',...
'the receiver chain). The filters are present in the simulation primarily for completeness. ',...
'SRRC filters are used in real-world spread spectrum systems to help ensure that tranmissions ',...
'do not become wider than necessary prior to being detected by the receiver (this may not make sense at ',...
'first, as one of the characteristics of spread spectrum is the generation of more bandwidth ',...
'than necessary to transmit a signal). The BPSK representation of your input signal is the ',...
'transmitter''s filter''s input, and its output is an upsampled version of the BPSK signal ',...
'(the upsampling takes place because the ratio of the filter''s sampling rate to the signal''s ',...
'defined sampling rate is 2:1). You might also notice that the amplitude of the filter''s output ',...
'is less than the input''s amplitude. This is corrected by the receiver''s filter (hence the ',...
'cascaded arrangement--the output of the first filter is the input of the second).'];
% SRRC #2 component window text
srrc_2_string = ['The receiver''s SQUARE ROOT RAISED COSINE FILTER is the first component in the ',...
'receiver chain. It corrects the amplitude changes applied by the transmitter''s filter, ',...
'but the upsampling remains (this is not a problem, though, as you will soon see).'];
% De-BPSK component window text
debpsk_string = ['The de-BINARY PHASE SHIFT KEYING component undoes the BPSK operation (i.e. determines ',...
'1s and 0s based on the received BPSK signal) using a method referred to as CORRELATION. First ',...
'the output of the receiver''s SRRC filter is trimmed to remove spurious data from the beginning ',...
'and end of the waveform. Next, each cycle is DOWNSAMPLED to match the size of the correlation ',...
'reference cycle (which represents a binary 1). The current downsampled cycle is then multiplied ',...
'with the reference cycle, and the product is used to determine a 1 or a 0 for that particular ',...
'cycle. Real-world systems use similar methods (but it is usually more complex, involving ',...
'techniques such as integrate-and-dump) because they are able to handle noise well (even if the ',...
'received BPSK signal was fairly noisy or imperfect, 3SA''s correlation method would still be able ',...
'to correctly identify the bits conveyed by the signal). The end-product of this component is ',...
'the same binary sequence that you transmitted earlier.'];
% DAC component window text
dac_string = ['DIGITAL to ANALOG CONVERSION is the reverse process of the ADC''s algorithm. The binary ',...
'sequence input into the DAC represents quantized data. After conversion back to integer form, ',...
'the polarity data is used to negate the appropriate values. The resulting data is then ',...
'denormalized and run through the Mu-law compander, this time for expansion. What results is a ',...
'very good APPROXIMATION of the spread signal produced by the Spread component.'];
% de-Spread component window text
despread_string = ['The de-SPREAD component is the final piece of the receiver chain. Here are plots of ',...
'the received spread and de-spread signals (please note that any changes you made with ',...
'the spreading tools will not be reflected here, as those changes were not a part of the full ',...
'simulation). Though the plot of the received voice signal LOOKS messy, you may be surprised ',...
'by the way this signal SOUNDS (here''s a hint--the Mu-law compression algorithm is meant to ',...
'trick your ears, not your eyes).'];
% Speakers component window text
spkrs_string = ['Here are the time domain plots of the input and received voice signals. The buttons ',...
'below will allow you to listen to both as well as save the received signal as a .wav file if you ',...
'choose to.'];
% Speakers component window outro text
spkrs_outro_string = ['And there you have it: a completed Direct Sequence Spread Spectrum communication.'];
% HEAR pushbutton callback
mic_hear_cb = ['global voice_data; global input_player; input_player = ',...
'audioplayer(voice_data, 8000); play(input_player);'];
% RECORD pushbutton callback
mic_rec_cb = ['acquire; plot(voice_data, ''blue''); title(''Input Signal''); ',...
'ylabel(''Perceived Pressure''); xlabel(''Sample'');'];
%-----------------------------UI/CALLBACK STRINGS----------------------------%
%----------------------------WINDOW LAUNCH CONTROL---------------------------%
% Decide which figure to launch based on button clicked.
switch button_clicked
case 'mic_pb'
% Create microphone window.
microphone = figure('position', microphone_dims,...
'menubar', 'none',...
'numbertitle', 'off',...
'resize', 'off',...
'name', '1. Voice Acquisition');
% Instructions.
micr_instructions = uicontrol(microphone,...
'style', 'text',...
'fontsize', micr_instructions_fontsize,...
'foregroundcolor', [.5 0 0],...
'backgroundcolor', [.8 .8 .8],... % same gray as GUI background
'horizontalalignment', 'center',...
'string', microphone_string,...
'units', 'normalized',...
'position', micr_instructions_dims);
% Create axes.
axes('position', mic_axes_dims, 'box', 'on');
axis([0 8000 -1 1]);
% Pushbuttons.
mic_rec = uicontrol(microphone,...
'style', 'pushbutton',...
'string', 'Record',...
'foregroundcolor', 'black',...
'fontsize', mic_pb_fontsize,...
'units', 'normalized',...
'position', mic_rec_dims,...
'callback', mic_rec_cb);
mic_open = uicontrol(microphone,...
'style', 'pushbutton',...
'string', 'Open',...
'foregroundcolor', 'black',...
'fontsize', mic_pb_fontsize,...
'units', 'normalized',...
'position', mic_open_dims,...
'callback', @mic_open_cb);
mic_hear = uicontrol(microphone,...
'style', 'pushbutton',...
'string', 'Hear',...
'foregroundcolor', 'black',...
'fontsize', mic_pb_fontsize,...
'units', 'normalized',...
'position', mic_hear_dims,...
'enable', 'off',... % button starts out inactive (no input specified at first)
'callback', mic_hear_cb);
mic_continue = uicontrol(microphone,...
'style', 'pushbutton',...
'string', 'Continue',...
'foregroundcolor', 'black',...
'fontsize', mic_pb_fontsize,...
'units', 'normalized',...
'position', mic_continue_dims,...
'enable', 'off',... % button starts out inactive
'callback', @mic_continue_cb);
case 'spread_pb'
% Create Spread window.
spread = figure('position', spread_dims,...
'menubar', 'none',...
'numbertitle', 'off',...
'resize', 'off',...
'name', '2. Spread',...
'CloseRequestFcn', 'global spread_input_player; stop(spread_input_player); delete(gcf);'); % kill long spread sounds if user closes this window
% Create axes for the input and spread signals and plot.
axes('position', spread_axes_1_dims, 'box', 'on');
plot(voice_data, 'blue');
title('Input Voice Signal');
ylabel('Perceived Pressure');
xlabel('Sample');
spread_axes = axes('position', spread_axes_2_dims, 'box', 'on');
plot(voice_data_spread, 'blue');
title('Spread Input Voice Signal');
ylabel('Perceived Pressure');
xlabel('Sample');
% Spreading factor input label/instructions.
spread_factor_field_instr = uicontrol(spread,...
'style', 'text',...
'fontsize', spread_factor_field_instr_fontsize,...
'foregroundcolor', 'blue',...
'backgroundcolor', [.8 .8 .8],... % same gray as GUI background
'horizontalalignment', 'center',...
'string', 'Press the ENTER key after typing your desired spreading factor below...',...
'units', 'normalized',...
'position', spread_factor_field_instr_dims); % just above the spreading factor enter field
% Spreading factor input field.
global spread_factor_field;
spread_factor_field = uicontrol(spread,...
'style', 'edit',...
'fontsize', spread_factor_field_fontsize,...
'string', num2str(walsh_factor),...
'units', 'normalized',...
'position', spread_factor_field_dims,...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -