0% found this document useful (0 votes)
5 views10 pages

Pseudo Code

The document provides pseudocode for generating and plotting various digital signal modulation techniques including BPSK, QPSK, 16QAM, and 64QAM, as well as visualizing OFDM subcarriers and simulating PAPR reduction techniques. Each section outlines the steps for generating random Gaussian values, converting them to bits, mapping to symbols, and plotting the resulting signals. Additionally, it includes methods for analyzing signal performance under different conditions and techniques.

Uploaded by

medofarajkhalifa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views10 pages

Pseudo Code

The document provides pseudocode for generating and plotting various digital signal modulation techniques including BPSK, QPSK, 16QAM, and 64QAM, as well as visualizing OFDM subcarriers and simulating PAPR reduction techniques. Each section outlines the steps for generating random Gaussian values, converting them to bits, mapping to symbols, and plotting the resulting signals. Additionally, it includes methods for analyzing signal performance under different conditions and techniques.

Uploaded by

medofarajkhalifa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Pseudocode

Pseudocode for Generating Digital Signal from Gaussi an


Random Values
Start

Set the number of bits to generate (e.g., 1000)

Generate a vector of random values using Gaussian (normal) distribution


→ Each value is from a standard normal distribution (mean = 0, std = 1)

Convert random values into binary bits:


→ If value > 0, set bit to 1
→ Else, set bit to 0

Plot the resulting bit sequence:


- Use circles connected by lines for visualization
- Set title: "Generated Signal"
- Label x-axis as "Bit Index"
- Label y-axis as "Value"
- Limit y-axis to slightly below 0 and above 1 for clarity
- Enable grid for better readability

End
Pseudocode for Generating and Plotting BPSK Signal
Start

Set the number of bits to generate (e.g., 1000)

Step 1: Generate random values

- Generate 1000 random values from a standard normal (Gaussian) distribution

Step 2: Convert random values to bits

- If a value > 0 → bit = 1

- If a value <= 0 → bit = 0

Step 3: Map bits to BPSK symbols

- If bit = 1 → symbol = +1

- If bit = 0 → symbol = -1

- This is done using: BPSK_symbol = 2 * bit - 1

Step 4: Plot the BPSK signal

- Use circle markers connected with lines to show transitions

- Add title: "BPSK Signal After Modulation"

- Label x-axis as "Sample Index"

- Label y-axis as "+1 or -1"

- Enable grid for visual clarity

End

Pseudocode for Generating and Plotting QPSK Signal


Start
Set number of bits to generate (e.g., 1000)

Step 1: Generate Gaussian random values

- Generate 1000 random values from a standard normal distribution

Step 2: Convert random values to bits (0 or 1)

- For each value:

If value > 0, bit = 1

Else, bit = 0

Step 3: Group bits into pairs (because QPSK uses 2 bits per symbol)

- Reshape the bit vector into 2 rows and N/2 columns

Step 4: Map each bit pair to a QPSK phase angle:

- Convert the 2-bit pair into a decimal number (0 to 3)

Example:

00 → 0

01 → 1

10 → 2

11 → 3

- Map these numbers to phase angles according to:

00 → -π/2

01 → +π/2

10 → +3π/4

11 → -3π/4

Step 5: Calculate constellation points:

- For each phase angle θ:

Compute (cos(θ), sin(θ))


Step 6: Plot constellation points:

- Use circles connected with lines for visualization

- Set title: "QPSK Signal After Modulation"

- Label x-axis as "In-phase component"

- Label y-axis as "Quadrature component"

- Enable grid

- Use equal axis scaling for accurate constellation shape

End

Pseudocode for Generating and Plotting 16QAM Signal


Start

 Set initial number of bits to generate (e.g., 1000)

 Check if the number of bits is a multiple of 4 (because 16 -QAM uses 4 bits


per symbol)

o If not multiple of 4:

 Increase numBits to the next multiple of 4

 Generate random Gaussian values of length numBits

 Convert random values to bits (0 or 1):

o For each value:

 If value > 0 → bit = 1

 Else → bit = 0

 Group bits into sets of 4 (reshape into 4 rows, each column is one 16 -QAM
symbol)

 Map each group of 4 bits into a decimal number:

o symbol_value = 2*bit1 + 2*bit2 + 4*bit3 + 8*bit4

 Shift symbols to be centered around zero:

o symbol_value = symbol_value - 8

 Plot constellation diagram for 16 -QAM:


o Plot each symbol’s real part on the x -axis

o Plot each symbol’s imaginary part on the y -axis

o Use scatter plot with circle markers

o Add title: "16-QAM Signal After Modulation"

o Label x-axis: "In-phase component"

o Label y-axis: "Quadrature component"

o Enable grid

o Use equal axis scaling to preserve the constellation shape

End

Pseudocode for Generating and Plotting 64QAM Signal


Start

 Set initial number of bits to generate (e.g., 1000)

 Check if the number of bits is a multiple of 6 (because 64-QAM uses 6 bits per symbol)

o If not a multiple of 6:

 Increase numBits to the next multiple of 6

 Generate random Gaussian values of length numBits

 Convert random values to bits (0 or 1):

o For each value:

 If value > 0, bit = 1

 Else, bit = 0

 Group bits into sets of 6 (reshape into 6 rows, each column represents one QAM
symbol)

 Map each group of 6 bits into a decimal number:

o symbol_value = 32*bit1 + 16*bit2 + 8*bit3 + 4*bit4 + 2*bit5 + bit6

 Shift symbol values to be centered around zero:

o symbol_value = symbol_value - 32

 Plot the constellation diagram for 64-QAM:

o Plot each symbol as a complex number (usually QAM symbols have both real (I)
and imaginary (Q) parts)
o Note: Current symbols are real numbers only; typically, QAM symbols should be
processed as complex numbers with I and Q components

o Use scatter plot

o Add title: "64-QAM Signal After Modulation"

o Label x-axis: "In-phase component"

o Label y-axis: "Quadrature component"

o Enable grid

o Set axis scaling to equal for proper display

End

Pseudocode for Visualizing OFDM Subcarriers in Time and


Frequency Domains
Start

Clear all variables and figures

Define different values of N (number of subcarriers)

Set number of OFDM symbols to 1

Set oversampling factor

Set sampling frequency (fs)

Set FFT size (Nfft)

For each N in N_values:

Compute sampling time Ts

Create a time vector 't' using oversampling

Generate QPSK symbols:

Generate complex Gaussian random numbers

Convert to QPSK by taking sign of real and imaginary parts

Normalize power
Generate OFDM signal in time domain using IFFT

Apply oversampling (interpolation) to the OFDM waveform

For each subcarrier from 1 to N:

Set only that subcarrier with data, others to zero

Apply IFFT to get its individual time-domain waveform

Interpolate the waveform for smooth plotting

Store each subcarrier waveform in a matrix

Generate distinguishable colors for plotting

Plot time-domain waveforms:

For each subcarrier:

Plot waveform vs time using assigned color

Add labels, grid, title, and legend

Plot frequency-domain spectrum:

Define frequency axis using FFT size

For each subcarrier:

Compute FFT and shift it to center

Plot the power spectrum in dB using assigned color

Add labels, grid, title, and legend

Zoom in on useful frequency range

Adjust y-axis to enhance visibility

End loop

Define helper function to generate distinguishable colors:


Use HSV color map and pick evenly spaced entries

Return color array

End

Pseudo Code for PAPR Reduction Techniques Simulation


Initialize parameters:

N = number of subcarriers (e.g., 64)

M = modulation order (e.g., 4 for QPSK)

numSymbols = number of OFDM symbols to simulate

SNRdB = range of SNR values (e.g., 0:5:30)

L = number of phase sequences for SLM

PTS_blocks = number of sub-blocks for PTS

clipRatio = clipping threshold for Clipping method

Initialize storage for results:

BER array for each SNR and technique

PAPR array for each technique

For each technique in [Clipping, SLM, PTS, TI, TR, LBC]:

For each SNR value in SNRdB:

Initialize totalErrors = 0, totalBits = 0

For each OFDM symbol from 1 to numSymbols:

Generate random bits of length 2*N (for QPSK)

Map bits to QPSK symbols using modulation

Apply the PAPR reduction technique:

If Clipping:
Perform IFFT on symbols to get time-domain signal

Clip signal amplitudes between -clipRatio and +clipRatio

Calculate PAPR

If SLM:

Generate L random phase sequences

Multiply symbols by each phase sequence

Perform IFFT and calculate PAPR for each

Choose sequence with minimum PAPR

If PTS:

Divide symbols into PTS_blocks sub-blocks

Search phase rotations from set {1, -1, j, -j}

Combine sub-blocks with phase rotations

Perform IFFT and select minimum PAPR combination

If TI:

Add small random perturbation to symbols

Perform IFFT and calculate PAPR

If TR:

Add tone reservation vector to symbols

Perform IFFT and calculate PAPR

If LBC:

Add parity bits for error correction

Modulate updated bits

Perform IFFT and calculate PAPR


Transmit signal over AWGN channel with current SNR

Receive and perform FFT to get frequency-domain signal

If technique is SLM or PTS:

Compensate received symbols by conjugate of chosen phase

Demodulate received symbols back to bits

Compare received bits to transmitted bits to count errors

Update totalErrors and totalBits

Calculate BER for current SNR and technique

Store PAPR results for current technique

Plot BER vs SNR for all techniques

Plot CCDF of PAPR for all techniques

Display average PAPR per technique

You might also like