【正文】
nd % points (at the discontinuites)% this reduces the effects of the discontinuities % it also distorts the desired frequency response (undesired side effect) % between Blackman, Hanning, and Hamming: Hamming introduces less distortion% note that the transpose of the Hamming function is % used (because a row vector is needed)% % Since all imaginary values of time_wave_matrix are practically equal to zero,% only the real part is retained for windowing. % for i = 1:symbols_per_carrier + 1 %windowed_time_wave_matrix(i,:) = real(time_wave_matrix(i,:)) .* hamming(IFFT_bin_length)39?!? windowed_time_wave_matrix(i,:) = real(time_wave_matrix(i,:))。end % % Serialize the modulating waveform % sequentially take each row of windowed_time_wave_matrix and construct a row vector % the row vector will be the modulating signal % note that windowed_time_wave_matrix is transposed, this is to account for the way the % Matlab 39。reshape39。 function works (reshape takes the columns of the target matrix and % appends them sequentially)% ofdm_modulation = reshape(windowed_time_wave_matrix39。, 1, IFFT_bin_length*(symbols_per_carrier+1))。 % % PLOT OFDM SIGNAL (time) % %temp_time = IFFT_bin_length*(symbols_per_carrier+1)。%figure (5) %plot(0:temp_time1,ofdm_modulation)%grid on %ylabel(39。Amplitude (volts)39。)%xlabel(39。Time (samples)39。) %title(39。OFDM Time Signal39。)% % PLOT OFDM SIGNAL (spectrum)%symbols_per_average = ceil(symbols_per_carrier/5)?! ?avg_temp_time = IFFT_bin_length*symbols_per_average?! ?averages = floor(temp_time/avg_temp_time)?!?average_fft(1:avg_temp_time) = 0?! ?for a = 0:(averages1)% subset_ofdm = ofdm_modulation(((a*avg_temp_time)+1):((a+1)*avg_temp_time))。% subset_ofdm_f = abs(fft(subset_ofdm))?!? average_fft = average_fft + (subset_ofdm_f/averages)?!?end %average_fft_log = 20*log10(average_fft)?!?figure (6) %plot((0:(avg_temp_time1))/avg_temp_time, average_fft_log) %hold on %plot(0:1/IFFT_bin_length:1, 35, 39。rd39。)%grid on%axis([0 40 max(average_fft_log)]) %ylabel(39。Magnitude (dB)39。) %xlabel(39。Normalized Frequency ( = fs/2)39。) %title(39。OFDM Signal Spectrum39。) % % ENDPLOT %% Upconversion to RF % % For this model, the baseband will be inserted directly into the channel % without conversion to RF frequencies. %Tx_data = ofdm_modulation?!? %CHANNEL ====================================================================== % % The channel model is Gaussian (AWGN) only % Rayleigh fading would be a useful addition %Tx_signal_power = var(Tx_data)。 %linear_SNR = 10^(SNR/10)。 noise_sigma = Tx_signal_power/linear_SNR?! oise_scale_factor = sqrt(noise_sigma)?! ? noise = randn(1, length(Tx_data))*noise_scale_factor?! x_Data = Tx_data + noise。% %%RECEIVE %% Convert the serial input data stream to parallel (according to symbol length % and number of symbols) % each column is a symbol period % the length of each symbol (samples per symbol) is the length of the % IFFT that was used to generate it% Rx_Data_matrix = reshape(Rx_Data, IFFT_bin_length, symbols_per_carrier + 1)。%% Transform each symbol from time to frequency domain% take the fft of each column% Rx_spectrum = fft(Rx_Data_matrix)。%% PLOT BASIC FREQUENCY DOMAIN REPRESENTATION%%figure (7) %stem(0:IFFT_bin_length1, abs(Rx_spectrum(1:IFFT_bin_length,2)),39。b*39。) %grid on %axis ([0 IFFT_bin_length ])%ylabel(39。Magnitude39。)%xlabel(39。FFT Bin39。) %title(39。OFDM Receive Spectrum, Magnitude39。) %figure (8)%plot(0:IFFT_bin_length1, (180/pi)*angle(Rx_spectrum(1:IFFT_bin_length,2)), 39。go39。) %hold on %stem(carriers1, (180/pi)*angle(Rx_spectrum(carriers,2)),39。b*39。)%stem(conjugate_carriers1, (180/pi)*angle(Rx_spectrum(conjugate_carriers,2)),39。b*39。) %axis ([0 IFFT_bin_length 200 +200]) %grid on %ylabel(39。Phase (degrees)39。) %xlabel(39。FFT Bin39。)%title(39。OFDM Receive Spectrum, Phase39。) %% END OF PLOTTING %% Extract the carrier FFT bins % only keep the fft bins that are used as carriers % take the transpose of the result so that each column will represent % a carrier % this is in preparation for using the diff( ) function later to decode % differential encoding% format following this operation is:% % C1s1 C2s1 C3s1 ...% C1s2 C2s2 C3s2 ... % C1s3 C2s3 C3s3 ...% . . .% . . . % % IMPORTANT MATLAB NOTE CONCERNING TRANSPOSING AND CONJUGATION% it appears that each time a matrix is transposed, the conjugate of % each value is taken % if an even number of transposes are done, then it is transparent % obviously, this does not affect real numbers % Rx_carriers = Rx_spectrum(carriers,:)39。%% PLOT EACH RECEIVED SYMBOL %figure (9) Rx_phase_P = angle(Rx_carriers)。 Rx_mag_P = abs(Rx_carriers)。 polar(Rx_phase_P, Rx_mag_P,39。bd39。)。 % % END PLOT % % Find the phase (angle) of each FFT bin (each carrier)% convert from radians to degrees % normalize phase to be between 0 and 359 degrees% Rx_phase = angle(Rx_carriers)*(180/pi)。 phase_negative = find(Rx_phase 0)。Rx_phase(phase_negative) = rem(Rx_phase(phase_negative)+360,360)?! ? % Extract phase differences (from the differential encoding) % the matlab diff( ) function is perfect for this operation % again, normalize the result to be between 0 and 359 degrees % Rx_decoded_phase = diff(Rx_phase)?!hase_negative = find(Rx_decoded_phase 0)?!x_decoded_phase(phase_negative) = rem(Rx_decoded_phase(phase_negative)+360,360)?!? % Convert phase to symbol %