www.gusucode.com > wlan 源码程序 matlab案例代码 > wlan/GenerateWLANWaveformsExample.m
%% Generate WLAN Waveforms % Generate S1G, VHT, HT-mixed, and non-HT format waveforms. Vary % configuration parameters and plot the waveforms to highlight differences % in waveforms and sample rates. %% % In each section of this example, you: % % * Create a format-specific configuration object. % * Create a vector of information bits for the packet data payload. % Internally, the |wlanWaveformGeneration| function loops through the bits % vector as many times as needed to generate the specified number of % packets. % * Generate the format-specific waveform and plot it. For plotting, % because no filtering is applied to the waveform and the oversampling rate % is 1, set the sampling rate equal to the channel bandwidth. %% Generate S1G Format Waveform % Create an S1G configuration object and waveform. Using |Name,Value| % pairs, specify 4 MHz channel bandwidth, 3 packets, and 15 microseconds of % idle time. Display the configuration object and inspect its properties % and settings. s1g = wlanS1GConfig('ChannelBandwidth','CBW4') bits = [1;0;0;1;1]; s1gWaveform = wlanWaveformGenerator(bits,s1g, ... 'NumPackets',3,'IdleTime',15e-6); %% % Plot the S1G format waveform, scaling the _x-axis_ relative to the % channel bandwidth. fs = 4e6; % Set sampling frequency equal to the channel bandwidth time = ([0:length(s1gWaveform)-1]/fs)*1e6; plot(time,abs(s1gWaveform)) xlabel ('Time (microseconds)'); ylabel('Magnitude'); %% % The plot shows three S1G format packets, with each packet separated by 15 % microseconds of idle time. %% Generate VHT Format Waveform % Create a VHT configuration object and waveform. Using |Name,Value| pairs, % specify 5 packets and 20 microseconds of idle time. Display the % configuration object and inspect its properties and settings. vht = wlanVHTConfig bits = [1;0;0;1;1]; vhtWaveform = wlanWaveformGenerator(bits,vht, ... 'NumPackets',5,'IdleTime',20e-6); %% % Plot the VHT format waveform, scaling the _x-axis_ relative to the % channel bandwidth. fs = 80e6; % Set sampling frequency equal to the channel bandwidth time = ([0:length(vhtWaveform)-1]/fs)*1e6; plot(time,abs(vhtWaveform)) xlabel ('Time (microseconds)'); ylabel('Magnitude'); %% % The plot shows five VHT format packets, with each packet separated by 20 % microseconds of idle time. %% Generate HT Format Waveform % Create an HT configuration object and waveform. Using |Name,Value| pairs, % specify 5 packets and 30 microseconds of idle time. Display the % configuration object and inspect its properties and settings. ht = wlanHTConfig bits = [1;0;0;1;1]; htWaveform = wlanWaveformGenerator(bits,ht, ... 'NumPackets',5,'IdleTime',30e-6); %% % Plot the HT format waveform, scaling the _x-axis_ relative to the channel % bandwidth. fs = 20e6; % Set sampling frequency equal to the channel bandwidth time = ([0:length(htWaveform)-1]/fs)*1e6; plot(time,abs(htWaveform)) xlabel ('Time (microseconds)'); ylabel('Magnitude'); %% % The plot shows five HT format packets, with 30 microseconds of idle time % separating each packet. %% Generate Non-HT Format DSSS Waveform % Create a non-HT configuration object and generate a non-HT format DSSS % waveform with a 2 Mbps data rate. Using |Name,Value| pairs, specify 2 % packets and 5 microseconds of idle time. Display the configuration object % and inspect its properties and settings. nht = wlanNonHTConfig('Modulation','DSSS','DataRate','2Mbps') bits = [1;0;0;1;1]; nhtDSSSWaveform = wlanWaveformGenerator(bits,nht, ... 'NumPackets',2,'IdleTime',5e-6); %% % Plot the non-HT Format DSSS waveform, scaling the _x-axis_ relative to % the channel bandwidth. As specified in IEEE 802.11-2012, Section 17.1.1, % the channel bandwidth is 11 MHz for DSSS. fs = 11e6; % Set sampling frequency equal to the channel bandwidth time = ([0:length(nhtDSSSWaveform)-1]/fs)*1e6; plot(time,real(nhtDSSSWaveform),'.') xlabel ('Time (microseconds)'); ylabel('Re[nhtDSSSWaveform]'); axis([8190,8200,-1.1,1.1]) %% % Sample values in DSSS modulation are –1 or 1. The plot shows the % real values for a section of the waveform that includes the tail end of % the first packet, the 5 microsecond idle period, and the beginning of the % second packet for the non-HT format DSSS modulated waveform. %% Generate Non-HT Format OFDM Waveform % Create a non-HT configuration object and waveform. Using |Name,Value| % pairs, specify 4 packets and 45 microseconds of idle time. Display the % configuration object and inspect its properties and settings. nht = wlanNonHTConfig bits = [1;0;0;1;1]; nhtWaveform = wlanWaveformGenerator(bits,nht, ... 'NumPackets',4,'IdleTime',45e-6); %% % Plot the non-HT format OFDM waveform, scaling the _x-axis_ relative to % the channel bandwidth. fs = 20e6; % Set sampling frequency equal to the channel bandwidth time = ([0:length(nhtWaveform)-1]/fs)*1e6; plot(time,abs(nhtWaveform)) xlabel ('Time (microseconds)'); ylabel('Magnitude'); %% % The plot shows four non-HT format OFDM modulated packets, with 45 % microseconds of idle time separating each packet.