Fortune Telling Collection - Zodiac Guide - How to generate OFDM time domain signal waveform with MATLAB

How to generate OFDM time domain signal waveform with MATLAB

Copy it to your Matlab and name it OFDM_Demo. Not only the one above you, but also the constellation, and so on.

Clear all;

All closed;

Carrier count = 200; Number of subcarriers%

Symbol per carrier =12; Percentage of symbols per subcarrier

Bits per symbol = 4; % bits per symbol, 16QAM modulation

IFFT _ Bin _ Length = 512; Percentage of FFT points

prefix ratio = 1/4; The percentage of guard interval to OFDM data is 1/6~ 1/4.

GI = prefix ratio * IFFT _ bin _ length; The length of the cyclic prefix% added to each OFDM symbol is 1/4*IFFT_bin_length, that is, the length of the guard interval is 128.

beta = 1/32; Roll-off coefficient of% window function

GIP = beta *(IFFT _ bin _ length+gi); Length of% cyclic suffix 20

SNR = 15; % SNR dB

%==================================================

% = = = = = = = = = = = Signal generation = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Baseband output length = carrier count * symbols per carrier * bits per symbol; Percentage of digits entered

Carriers = (1:carrier _ count)+(floor (IFFT _ bin _ length/4)-floor (carrier _ count/2)); IFFT point coordinates of complex data corresponding to% * * yoke symmetric subcarrier mapping.

Conjugate _ carrier = IFFT _ bin _ length-carrier+2; % * * * yoke symmetric subcarrier mapping * * * IFFT point coordinates corresponding to yoke complex number.

rand( 'state ',0);

Baseband _out=round(rand( 1, baseband _ out _ length));); % output the binary bit stream to be modulated

% = = = = = = = = = =16 QAM modulation = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Complex number _ carrier _ matrix =qam 16 (baseband _ output); % column vector

complex _ carrier _ matrix = reshape(complex _ carrier _ matrix ',carrier_count,symbols _ per _ carrier)'; Percentage of symbols per carrier * carrier count matrix

Figure (1);

plot(complex_carrier_matrix,' * r '); Constellation map after% 16QAM modulation

Axis ([-4,4,-4,4]);

Grid open

% = = = = = = = = = = = = = = = = = IFFT = = = = = = = = = = = = = = = = = = = = = =

IFFT _ modulation = zero (per carrier symbol, IFFT _ bin _ length); % plus 0 constitutes IFFT_bin_length IFFT operation.

IFFT _ modulation (:,carrier) = complex _ carrier _ matrix; % pilot signal is not added, and subcarrier is mapped here.

IFFT _ modulation (:,conjugate _ carrier) = conj (complex _ carrier _ matrix); % * * * yoke complex mapping

%========================================================

Figure (2);

Stem (0: IFFT _ bin _ length-1,ABS (IFFT _ modulation (2, 1: IFFT _ bin _ length)),' b *-')% frequency spectrum of the first OFDM symbol.

Grid open

Axis ([0IFFT _ bin _ length-0.54.5]);

Ylabel ('magnitude');

Xlabel ("IFFT Bin");

Title ("OFDM carrier frequency amplitude");

Fig. 3;

Plot (0: IFFT _ bin _ length-1,(kloc-0/80/pi) * angle (IFFT _ modulation (2, 1:IFFT_bin_length)),' go')

continue

Stem(0: carrier-1, (180/pi)* angle (IFFT _ modulation (2, 1: carrier)),' b *-'); % phase of the first OFDM symbol

Stem(0: conjugate _ carrier-1, (kloc-0/80/pi) * angle (IFFT _ modulation (2, 1: conjugate _ carrier)),' b *-');

Axis ([0 IFFT _ bin _ length -200 +200])

Grid open

Ylabel ('phase (degree)')

Xlabel ("IFFT Bin")

Title ("OFDM carrier phase")

%=================================================================

Signal _ after _ IFFT = IFFT(IFFT _ modulation, IFFT_bin_length, 2); %OFDM modulation is IFFT transform.

Time _ wave _ matrix = signal _ after% time domain waveform matrix, indicating the number of symbols of each carrier, listing ITTF points, in which N subcarriers are mapped, and each line is an OFDM symbol.

Fig. 4;

Subplots (3, 1,1);

Plot (0: IFFT _ bin _ length-1,time _ wave _ matrix (2,)); The% waveform of the first symbol

Axis ([0,700, -0.2, 0.2]);

Grid open;

Ylabel ('amplitude');

xlabel(' Time ');

Title ("OFDM time signal, one symbol period");

%===========================================================

% = = = = = = = = = = = Add a cyclic prefix and suffix = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

XX = zero (symbol _ per carrier, IFFT _ bin _ length+GI+GIP);

For k= 1: number of symbols per carrier;

For I =1:IFFT _ bin _ length;

XX(k,i+GI)=signal_after_IFFT(k,I);

end

For I =1:gi;

XX(k,i)=signal_after_IFFT(k,I+IFFT _ bin _ length-GI); % Add cyclic prefix

end

For j =1:GIP;

XX(k,IFFT _ bin _ length+GI+j)= signal _ after _ IFFT(k,j); % Add cyclic suffix

end

end

Time _ wave _ matrix _ cp = XX% time domain signal matrix with cyclic prefix and suffix, and the length of OFDM symbol is IFFT_bin_length+GI+GIP=660.

Subplots (3, 1, 2);

plot(0:length(time _ wave _ matrix _ CP)- 1,time_wave_matrix_cp(2,); % Waveform with cyclic prefix added to the first symbol

Axis ([0,700, -0.2, 0.2]);

Grid open;

Ylabel ('amplitude');

xlabel(' Time ');

Title ("OFDM time signal with CP, one symbol period");

% = = = = = = = = = = = = OFDM symbol windowing = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

windowed _ time _ wave _ matrix _ CP = zeros( 1,IFFT _ bin _ length+GI+GIP);

For i = 1: number of symbols per carrier

windowed_time_wave_matrix_cp(i,)= real(time_wave_matrix_cp(i,))。 *rcoswindow(beta,IFFT _ bin _ length+GI)'; % window raised cosine window

end

Subplots (3, 1, 3);

Plot (0: IFFT _ bin _ length-1+gi+GIP, windowed _ time _ waveform _ matrix _cp(2,); The% waveform of the first symbol

Axis ([0,700, -0.2, 0.2]);

Grid open;

Ylabel ('amplitude');

xlabel(' Time ');

Title ("OFDM time signal applies one window and one symbol period");

% = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

windowed_Tx_data=zeros( 1,symbols _ per _ carrier *(IFFT _ bin _ length+GI)+GIP);

windowed _ Tx _ data( 1:IFFT _ bin _ length+GI+GIP)= windowed _ time _ wave _ matrix _ CP( 1,);

For i = 1: symbol _ per carrier-1;

windowed _ Tx _ data((IFFT _ bin _ length+GI)* I+ 1:(IFFT _ bin _ length+GI)*(I+ 1)+GIP)= windowed _ time _ wave _ matrix _ CP(I+ 1,); % parallel-serial conversion, cyclic suffix and cyclic prefix superposition.

end

%=======================================================

tx _ data _ without window = shape(time _ wave _ matrix _ CP ',(symbols _ per _ carrier)*(IFFT _ bin _ length+GI+GIP), 1)'; % serial signal has no window, only cyclic prefix and suffix are added.

tx _ data = shape(windowed _ time _ wave _ matrix _ CP ',(symbols _ per _ carrier)*(IFFT _ bin _ length+GI+GIP), 1)'; Serial signals with cyclic prefixes and suffixes are not superimposed after% windowing.

%=================================================================

temp _ time 1 =(symbols _ per _ carrier)*(IFFT _ bin _ length+GI+GIP); % After the window is opened, the cyclic prefix and suffix do not overlap to send the total number of digits.

Figure (5)

Subplots (2, 1,1);

plot(0:temp _ time 1- 1,Tx _ data); % cyclic prefix and suffix do not overlap with the transmitted signal waveform.

Grid open

Ylabel ('amplitude (volts)')

Xlabel ('time (sample)')

Title ("OFDM time signal")

temp _ time 2 = symbols _ per _ carrier *(IFFT _ bin _ length+GI)+GIP;

Subplots (2, 1, 2);

plot(0:temp_time2- 1,windowed _ Tx _ data); The% cyclic suffix is superimposed with the cyclic prefix to send the signal waveform.

Grid open

Ylabel ('amplitude (volts)')

Xlabel ('time (sample)')

Title ("OFDM time signal")

% = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

symbols _ per _ average = ceil(symbols _ per _ carrier/5); 1/5, 10% number of symbols

avg _ temp _ time =(IFFT _ bin _ length+GI+GIP)* symbols _ per _ average; % dot, 10 line data, 10 symbol.

Average value = floor (temp _ time1/avg _ temp _ time);

average _ FFT( 1:avg _ temp _ time)= 0; % is divided into five parts

For a = 0: (average-1)

subset _ OFDM = Tx _ data _ without window((a * avg _ temp _ time)+ 1):((a+ 1)* avg _ temp _ time); %

subset _ OFDM _ f = ABS(FFT(subset _ OFDM)); % will send the spectrum of the signal segment.

average _ FFT = average _ FFT+(subset _ OFDM _ f/averages); Divide% of the total * * * data into five segments, perform FFT on each segment, and add them on average.

end

average _ FFT _ log = 20 * log 10(average _ FFT);

Figure (6)

Subplots (2, 1,1);

Plot ((0: (avg _ temp _ time-1))/avg _ temp _ time, average _ FFT _ log)% normalized 0/avg _ temp _ time: (avg _ temp _ time-1)/avg _ temp.

continue

plot(0: 1/IFFT _ bin _ length: 1,-35,' rd ')

Grid open

Axis ([0 0.5 -40 max (average_fft_log)])

Ylabel ('amplitude (dB)')

Xlabel ('normalized frequency (0.5 = fs/2)')

Title ("windowless OFDM signal spectrum")

% = = = = = = = = = = = Spectrum of windowed transmitted signal = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

symbols _ per _ average = ceil(symbols _ per _ carrier/5); 1/5, 10% number of symbols

avg _ temp _ time =(IFFT _ bin _ length+GI+GIP)* symbols _ per _ average; % dot, 10 line data, 10 symbol.

Average value = floor (temp _ time1/avg _ temp _ time);

average _ FFT( 1:avg _ temp _ time)= 0; % is divided into five parts

For a = 0: (average-1)

subset _ OFDM = Tx _ data((a * avg _ temp _ time)+ 1):((a+ 1)* avg _ temp _ time); % Use the serial windowed signal whose cyclic prefix suffix is not superimposed to calculate the spectrum.

subset _ OFDM _ f = ABS(FFT(subset _ OFDM)); % segmented spectrum

average _ FFT = average _ FFT+(subset _ OFDM _ f/averages); Divide% of the total * * * data into five segments, perform FFT on each segment, and add them on average.

end

average _ FFT _ log = 20 * log 10(average _ FFT);

Subplots (2, 1, 2)

Plot ((0: (avg _ temp _ time-1))/avg _ temp _ time, average _ FFT _ log)% normalized 0/avg _ temp _ time: (avg _ temp _ time-1)/avg _ temp.

continue

plot(0: 1/IFFT _ bin _ length: 1,-35,' rd ')

Grid open

Axis ([0 0.5 -40 max (average_fft_log)])

Ylabel ('amplitude (dB)')

Xlabel ('normalized frequency (0.5 = fs/2)')

Title ("windowed OFDM signal spectrum")

% = = = = = = = = = = = = Add noise = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Tx _ signal _ power = var(windowed _ Tx _ data); % transmit signal power

linear_snr= 10^(snr/ 10); % linear SNR

noise _σ= Tx _ signal _ power/linear _ SNR;

Noise _ scale _ factor = sqrt (noise _ sigma); Standard deviation percentage sigma

Noise=randn( 1, ((symbol _ per carrier) *(IFFT _ bin _ length+gi))+GIP) * noise _ scale _ factor; % produces a noise sequence with normal distribution.

%noise=wgn( 1, length(windowed_Tx_data), noise_sigma,' complex number'); % produce complex Gaussian white noise signal.

rx _ data = windowed _ Tx _ data+noise; % received signal plus noise

% = = = = = = = = = = = Received signal string/parallel transformation to remove prefix and suffix = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Rx_data_matrix=zeros (symbol _ per carrier, IFFT _ bin _ length+GI+GIP);

For i= 1: number of symbols per carrier;

Rx_data_matrix(i,)=Rx_data( 1,(I- 1)*(IFFT _ bin _ length+GI)+ 1:I *(IFFT _ bin _ length+GI)+GIP); % serial-parallel conversion

end

Rx _ data _ complex _ matrix = Rx _ data _ matrix(:,GI+ 1:IFFT _ bin _ length+GI); % Remove cyclic prefix and cyclic suffix to get useful signal matrix.

%============================================================%================================================================

%==============================================================

% OFDM decoding 16QAM decoding

% = = = = = = = = = = = FFT Transform = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

y 1 = FFT(Rx _ data _ complex _ matrix,IFFT_bin_length,2); %OFDM decoding is FFT transform.

Rx_carriers=Y 1(:,carriers); % Divide the zero added by IFFT/FFT transform and select the mapped subcarrier.

Rx _ phase = angle (rx _ carriers); Phase percentage of received signal

Rx _ mag = ABS(Rx _ carriers); % amplitude of received signal

Fig. 7;

Polar coordinates (Rx_phase, Rx_mag,' BD'); Draw the constellation of the received signal in% polar coordinates.

%======================================================================

[M,N]=pol2cart(Rx_phase,Rx _ mag);

Rx_complex_carrier_matrix = complex number (m, n);

Fig. 8;

plot(Rx_complex_carrier_matrix,' * r '); Constellation diagram of received signal in %XY coordinates

Axis ([-4,4,-4,4]);

Grid open

% = = = = = = = = = = = = = = =16 QAM demodulation = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Rx _ serial _ complex _ symbols = reshape(Rx _ complex _ carrier _ matrix ',size(Rx_complex_carrier_matrix, 1)* size(Rx _ complex _ carrier _ matrix,2), 1)';

Rx _ decoded _ binary _ symbols = demoduqam 16(Rx _ serial _ complex _ symbols);

%============================================================

Baseband _ input = receive _ decode _ binary _ symbol;

Fig. 9;

Subplots (2, 1,1);

Stem (baseband _ out (1:100));

Subplots (2, 1, 2);

Stem (baseband _ in (1:100));

% = = = = = = = = = = = = Error rate calculation = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Bit_errors=find (baseband _ in ~ = baseband _ out);

Bit error count = size (bit error, 2)

Ber = bit error count/baseband output length