BPSK Explaination

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

‭BPSK OFDM MATLAB CODE‬

‭lc;‬
c
close‬‭
‭ all‬
;‬

M = 2;‬

data = 64;‬

blocksize = 8;‬

cp = 2;‬

input = randi([0, 1], 1, data);‬

figure(1)‬

stem(input)‬

title(‬
‭ 'Transmitted data'‬
‭ )‬

xlabel(‬
‭ 'data points'‬
‭ )‬

ylabel(‬
‭ 'Transmitted data phase represntation'‬
‭ )‬

bpskmod = input * 2 - 1;‬

figure(2)‬

scatter(real(bpskmod), imag(bpskmod),‬‭
‭ 'o'‬
);‬

title(‬
‭ 'BPSK modulated'‬
‭ )‬

xlabel(‬
‭ 'in phase'‬
‭ )‬

ylabel(‬
‭ 'quadrature phase'‬
‭ )‬

ofdm = [];‬

for‬‭
‭ i = 1:blocksize:data‬
bd = bpskmod(i:i + blocksize - 1);‬

of = ifft([bd zeros(1, cp)], blocksize);‬

ofdm = [ofdm, of];‬

end‬

figure(3)‬

plot(abs(ofdm))‬

title(‬
‭ 'OFDM modulated'‬
‭ )‬

xlabel(‬
‭ 'Time'‬
‭ )‬

ylabel(‬
‭ 'Amplitude'‬
‭ )‬

demod = [];‬

for‬‭
‭ i = 1:blocksize:length(ofdm)‬
rb = ofdm(i:i + blocksize - 1);‬

demodblock = fft(rb, blocksize);‬‭
‭ % Normalize by dividing by block size‬
demod = [demod, demodblock];‬

end‬

demod_bpsk_symbols = real(demod) >= 0;‬

figure(4)‬

scatter(real(demod_bpsk_symbols), imag(demod_bpsk_symbols),‬‭
‭ 'o'‬
);‬

title(‬
‭ 'BPSK demodulated'‬
‭ )‬

xlabel(‬
‭ 'in phase'‬
‭ )‬

ylabel(‬
‭ 'quadrature phase'‬
‭ )‬

figure(5)‬

stem(demod_bpsk_symbols)‬

title(‬
‭ 'Received BPSK symbols'‬
‭ )‬

xlabel(‬
‭ 'data points'‬
‭ )‬

ylabel(‬
‭ 'Received data phase represntation'‬
‭ )‬

‭EXPLAINATION‬
‭●‬ M ‭ = 2;: This variable M is assigned the value 2. In digital communication, the‬
‭parameter M often represents the modulation order, which is the number of symbols in‬
‭the modulation scheme. In this case, M = 2 suggests Binary Phase Shift Keying‬
‭(BPSK), where there are two possible symbols (0 and 1).‬
‭●‬ ‭data = 64;: This variable data is assigned the value 64. It represents the number of data‬
‭points or bits in the binary input sequence that will be generated later in the code. In‬
‭the context of the script, it determines the length of the random binary input sequence.‬
‭●‬ ‭blocksize = 8;: This variable blocksize is assigned the value 8. It represents the size of‬
‭each block in the OFDM modulation scheme. OFDM (Orthogonal Frequency Division‬
‭Multiplexing) divides the data into blocks, and each block is processed separately.‬
‭●‬ ‭cp = 2;: This variable cp is assigned the value 2. It represents the size of the cyclic‬
‭prefix (CP) in the OFDM symbols. The cyclic prefix is a copy of the end of the‬
‭OFDM symbol that is prepended to the beginning. It helps in dealing with the effects‬
‭of channel delay spread and simplifies the equalization process at the receiver.‬
‭●‬ ‭A random binary input sequence of length data is generated using randi function. This‬
‭sequence represents the data to be transmitted.‬
‭●‬ ‭figure(1): This command creates a new figure with the figure number specified inside‬
‭the parentheses. In this case, figure(1) creates the first figure. Figures are containers‬
‭for plots and other graphical elements.‬
‭●‬ ‭stem(input): This command creates a stem plot of the input variable. In MATLAB, a‬
‭stem plot is similar to a discrete sequence plot, where vertical lines (stems) are used to‬
‭represent data values. The input variable likely contains a binary sequence of data‬
‭points (0s and 1s), and the stem plot visually represents this sequence.‬
‭●‬ ‭title('Transmitted data'): This command sets the title of the current axes to 'Transmitted‬
‭data'. The title provides a brief description of what is being visualized in the plot.‬
‭●‬ ‭xlabel('data points'): This command labels the x-axis of the plot with 'data points'. It‬
‭indicates the quantity or meaning of the data points along the horizontal axis.‬
‭●‬ ‭ylabel('Transmitted data phase representation'): This command labels the y-axis of the‬
‭plot with 'Transmitted data phase representation'. It indicates the quantity or meaning‬
‭of the transmitted data's phase representation along the vertical axis.‬
‭●‬ ‭In Binary Phase Shift Keying (BPSK), mapping refers to the process of assigning‬
‭complex symbols to each binary bit. The key characteristic of BPSK is that there are‬
‭only two possible symbols, typically denoted as‬
‭●‬ ‭+1‬
‭●‬ ‭+1 and‬
‭●‬ ‭−1‬
‭●‬ ‭−1, representing binary 1 and binary 0, respectively.‬
‭●‬ ‭Let's break down the mapping process in BPSK:‬
‭●‬ ‭Binary Input Sequence:‬
‭○‬ ‭The input is a binary sequence, consisting of bits that can take values of 0 or 1‬
‭(e.g.,‬
‭○‬ ‭010110‬
‭○‬ ‭010110).‬
‭●‬ ‭Mapping to Complex Symbols:‬
‭○‬ ‭For BPSK, each binary bit is mapped to a complex symbol:‬
‭■‬ ‭Binary 0 is mapped to a complex symbol with a negative amplitude (‬
‭■‬ ‭−1‬
‭■‬ ‭−1).‬
‭■‬ ‭Binary 1 is mapped to a complex symbol with a positive amplitude (‬
‭■‬ ‭+1‬
‭■‬ ‭+1).‬
‭●‬ ‭This mapping is often achieved using the following formula:‬
‭○‬
‭○‬ ‭BPSK Symbol=2×Binary Bit−1‬
‭○‬ ‭BPSK Symbol=2×Binary Bit−1‬
‭■‬ ‭If the binary bit is 0, then‬
‭■‬ ‭2×0−1=−1‬
‭■‬ ‭2×0−1=−1.‬
‭■‬ ‭If the binary bit is 1, then‬
‭■‬ ‭2×1−1=1‬
‭■‬ ‭2×1−1=1.‬
‭●‬ ‭Example:‬
‭○‬ ‭Suppose the binary input sequence is‬
‭○‬ ‭010110‬
‭○‬ ‭010110.‬
‭○‬ ‭The corresponding BPSK-modulated symbols would be‬
‭○‬ ‭−1,1,−1,1,1‬
‭○‬ ‭−1,1,−1,1,1.‬
‭●‬ ‭figure(2): This command creates a new figure with the figure number specified inside‬
‭the parentheses. In this case, figure(2) creates the second figure. Each figure provides‬
‭a separate space for plotting, and multiple figures can be used to organize different‬
‭visualizations.‬
‭●‬ ‭scatter(real(bpskmod), imag(bpskmod), 'o'):‬
‭○‬ ‭real(bpskmod): Retrieves the real part (in-phase component) of the‬
‭BPSK-modulated symbols stored in the bpskmod variable.‬
‭○‬ ‭imag(bpskmod): Retrieves the imaginary part (quadrature-phase component) of‬
‭the BPSK-modulated symbols.‬
‭○‬ ‭'o': Specifies that the data points should be plotted as circles.‬
‭●‬ ‭This line creates a scatter plot where the x-axis represents the in-phase component, the‬
‭y-axis represents the quadrature-phase component, and each symbol is represented by‬
‭a circle in the complex plane.‬
‭●‬ t‭itle('BPSK modulated'): This command sets the title of the current axes to 'BPSK‬
‭modulated'. The title provides a brief description of what is being visualized in the‬
‭plot.‬
‭●‬ ‭xlabel('in phase'): This command labels the x-axis of the plot with 'in phase'. It‬
‭indicates the in-phase component (real part) of the BPSK-modulated symbols along‬
‭the horizontal axis.‬
‭●‬ ‭ylabel('quadrature phase'): This command labels the y-axis of the plot with 'quadrature‬
‭phase'. It indicates the quadrature-phase component (imaginary part) of the‬
‭BPSK-modulated symbols along the vertical axis.‬
‭●‬ ‭This block of code uses a loop to process the BPSK-modulated symbols (bpskmod) in‬
‭blocks of size blocksize. The loop iterates from 1 to the total number of data points‬
‭(data), and in each iteration:‬
‭●‬ ‭bd = bpskmod(i:i + blocksize - 1);: It extracts a block of BPSK-modulated symbols of‬
‭size blocksize from the bpskmod sequence.‬
‭●‬ ‭of = ifft([bd zeros(1, cp)], blocksize);: It appends zeros to the end of the block to‬
‭account for the cyclic prefix (CP). Then, it performs the Inverse Fast Fourier‬
‭Transform (IFFT) on the extended block. The IFFT is applied to convert the‬
‭time-domain signal into the frequency-domain OFDM symbol.‬
‭●‬ ‭ofdm = [ofdm, of];: It concatenates the OFDM symbol (of) to the ofdm array.‬
‭●‬ ‭This loop processes the OFDM-modulated signal (ofdm) in blocks of size blocksize.‬
‭The loop iterates from 1 to the total length of the OFDM signal (length(ofdm)), and in‬
‭each iteration:‬
‭●‬ ‭rb = ofdm(i:i + blocksize - 1);: It extracts a block of the OFDM-modulated signal of‬
‭size blocksize.‬
‭●‬ ‭demodblock = fft(rb, blocksize);: It performs the Fast Fourier Transform (FFT) on the‬
‭block to convert it from the time domain to the frequency domain. The resulting‬
‭demodblock represents the frequency-domain symbols.‬
‭●‬ ‭% Normalize by dividing by block size: The comment indicates that the normalization‬
‭is done by dividing each element of demodblock by the block size. This normalization‬
‭step is often necessary in OFDM systems.‬
‭●‬ ‭demod = [demod, demodblock];: It concatenates the demodulated symbols‬
‭(demodblock) to the demod array.‬
‭●‬ ‭real(demod): Extracts the real part (in-phase component) of the demodulated symbols‬
‭stored in the demod array. In the context of BPSK, this real part represents the‬
‭amplitude of the received symbols after demodulation.‬
‭●‬ ‭>= 0: Compares each element of the real part to zero. The result is a logical array‬
‭where each element is 1 if the corresponding element in the real part is greater than or‬
‭equal to zero, and 0 otherwise.‬
‭●‬ ‭demod_bpsk_symbols = ...: Assigns the logical array to the variable‬
‭demod_bpsk_symbols. Each 1 in this array indicates that the corresponding‬
‭demodulated symbol has a positive amplitude, and each 0 indicates that the symbol‬
‭has a negative amplitude.‬
‭●‬ I‭ n the context of BPSK, this step is used to make a decision on whether the received‬
‭symbol is a 1 or a 0 based on the sign of the real part after demodulation. If the real‬
‭part is greater than or equal to zero, it is considered a 1; otherwise, it is considered a 0.‬
‭This is a common method for demodulating BPSK signals because BPSK symbols are‬
‭represented by their sign in the real part of the received signal.‬
‭●‬ ‭This block of code creates the fourth figure, and it visualizes the demodulated BPSK‬
‭symbols in the complex plane using a scatter plot.‬
‭●‬ ‭scatter(real(demod_bpsk_symbols), imag(demod_bpsk_symbols), 'o'):‬
‭○‬ ‭real(demod_bpsk_symbols): Retrieves the real part (in-phase component) of the‬
‭demodulated BPSK symbols.‬
‭○‬ ‭imag(demod_bpsk_symbols): Retrieves the imaginary part (quadrature-phase‬
‭component) of the demodulated BPSK symbols.‬
‭○‬ ‭'o': Specifies that the data points should be plotted as circles.‬
‭●‬ ‭title('BPSK demodulated'): Sets the title of the scatter plot to 'BPSK demodulated'.‬
‭●‬ ‭xlabel('in phase'): Labels the x-axis of the plot with 'in phase', indicating the in-phase‬
‭component of the demodulated symbols.‬
‭●‬ ‭ylabel('quadrature phase'): Labels the y-axis of the plot with 'quadrature phase',‬
‭indicating the quadrature-phase component of the demodulated symbols.‬
‭●‬ ‭This block of code creates the fifth figure, and it visualizes the received BPSK‬
‭symbols using a stem plot.‬
‭●‬ ‭stem(demod_bpsk_symbols): Creates a stem plot of the received BPSK symbols. The‬
‭vertical lines indicate the values of the received symbols.‬
‭●‬ ‭title('Received BPSK symbols'): Sets the title of the stem plot to 'Received BPSK‬
‭symbols'.‬
‭●‬ ‭xlabel('data points'): Labels the x-axis of the plot with 'data points', indicating the‬
‭position of each data point in the received symbols.‬
‭●‬ ‭ylabel('Received data phase representation'): Labels the y-axis of the plot with‬
‭'Received data phase representation', indicating the representation of the received data‬
‭in the phase domain.‬
‭●‬

You might also like