Skip to main content

Robust Signal Detection with Prefix and Postfix in MATLAB

 

MATLAB Code

clc;
clear;
close all;

% Parameters
fs = 1000; % Sampling frequency
msgLength = 100; % Length of the message
pnLength = 50; % Length of PN sequence
silenceLength = 20; % Length of silence before and after
lagAmount = 50; % Amount of lag (can be negative for lead)
threshold = 0.5; % Threshold for correlation peak detection

% Generate Unique PN Sequences
pnPrefix = 2 * (randi([0, 1], 1, pnLength) - 0.5);
pnPostfix = 2 * (randi([0, 1], 1, pnLength) - 0.5);

% Generate Message
originalMessage = (randi([0, 1], 1, msgLength));
message = 2*originalMessage - 1;

% Construct Dataframe
dataframe = [pnPrefix, message, pnPostfix];

% Introduce Lag or Lead
if lagAmount > 0
%laggedFrame = [zeros(1, lagAmount), dataframe(1:end - lagAmount)];
laggedFrame = [zeros(1, lagAmount), dataframe];
else
laggedFrame = [dataframe(-lagAmount + 1:end), zeros(1, -lagAmount)];
end

% Correlation with PN Sequences
corrPrefix = xcorr(laggedFrame, pnPrefix);
corrPostfix = xcorr(laggedFrame, pnPostfix);

% Normalize Correlation
corrPrefix = corrPrefix / max(corrPrefix);
corrPostfix = corrPostfix / max(corrPostfix);

% Adjust indices to align with laggedFrame
corrLen = length(laggedFrame);
prefixIndices = (1:length(corrPrefix)) - corrLen;
postfixIndices = (1:length(corrPostfix)) - corrLen;

% Detect Peaks in Correlation (Apply Threshold)
prefixPeaks = prefixIndices(corrPrefix > threshold);
postfixPeaks = postfixIndices(corrPostfix > threshold);

% Estimate Start and End of Message
if ~isempty(prefixPeaks)
startMessage = max(1, prefixPeaks(1) + length(pnPrefix));
else
startMessage = -1; % Detection failed
end

if ~isempty(postfixPeaks)
endMessage = min(length(laggedFrame), postfixPeaks(end) - length(pnPostfix) - 1);
else
endMessage = -1; % Detection failed
end

% Retrieve Original Message
if startMessage > 0 && endMessage > 0 && endMessage > startMessage
retrievedMessage = laggedFrame(startMessage+1:endMessage+pnLength+1)>0;
else
retrievedMessage = [];
end

% Display Original Message
disp('Original Message:'), disp(originalMessage);

% Display Results
disp('Retrieved Message:'), disp(retrievedMessage);

% Plot Results
figure;
subplot(3, 1, 1); plot(dataframe); title('Original Dataframe');
subplot(3, 1, 2); plot(laggedFrame); title('Lagged/Lead Dataframe');
subplot(3, 1, 3); plot(corrPrefix, 'b'); hold on; plot(corrPostfix, 'r');
title('Correlation with PN Sequences');
legend('Prefix Correlation', 'Postfix Correlation');

 

Output 

 Original Message:

     1     0     0     0     1     1     0     1     1     0     0     0     0     1     0     0     1     1     0     1     1  ......
 
Retrieved Message:

    1     0     0     0     1     1     0     1     1     0     0     0     0     1     0     0     1     1     0     1     1  ......
 
 










Copy the aforementioned MATLAB Code from here

 

 

Further Reading

 

Contact Us

Name

Email *

Message *

Popular Posts

BER vs SNR for M-ary QAM, M-ary PSK, QPSK, BPSK, ...(MATLAB Code + Simulator)

Bit Error Rate (BER) & SNR Guide Analyze communication system performance with our interactive simulators and MATLAB tools. 📘 Theory 🧮 Simulators 💻 MATLAB Code 📚 Resources BER Definition SNR Formula BER Calculator MATLAB Comparison 📂 Explore M-ary QAM, PSK, and QPSK Topics ▼ 🧮 Constellation Simulator: M-ary QAM 🧮 Constellation Simulator: M-ary PSK 🧮 BER calculation for ASK, FSK, and PSK 🧮 Approaches to BER vs SNR What is Bit Error Rate (BER)? The BER indicates how many corrupted bits are received compared to the total number of bits sent. It is the primary figure of merit f...

OFDM Symbols and Subcarriers Explained

This article explains how OFDM (Orthogonal Frequency Division Multiplexing) symbols and subcarriers work. It covers modulation, mapping symbols to subcarriers, subcarrier frequency spacing, IFFT synthesis, cyclic prefix, and transmission. Step 1: Modulation First, modulate the input bitstream. For example, with 16-QAM , each group of 4 bits maps to one QAM symbol. Suppose we generate a sequence of QAM symbols: s0, s1, s2, s3, s4, s5, …, s63 Step 2: Mapping Symbols to Subcarriers Assume N sub = 8 subcarriers. Each OFDM symbol in the frequency domain contains 8 QAM symbols (one per subcarrier): Mapping (example) OFDM symbol 1 → s0, s1, s2, s3, s4, s5, s6, s7 OFDM symbol 2 → s8, s9, s10, s11, s12, s13, s14, s15 … OFDM sym...

UGC NET Electronic Science Previous Year Question Papers with Solutions

Home / Engineering & Other Exams / UGC NET 2026 PYQ ⬇️ Download Papers and Solutions 📋 Exam Pattern 💡 Preparation Tips ❓ FAQs 📊 Exam Highlights: Electronic Science (88) Feature Details Junior Research Fellowship (JRF) ₹37,000 + HRA per month Eligibility M.Sc/M.Tech in Electronics (55%) Validity of Certificate JRF (3 Years) | Lectureship (Lifetime) 📥 Download UGC NET Electronics PDFs Complete collection of previous year question papers, answer keys and explanations for Subject Code 88. Start Downloading 📂 View All Question Papers June 2025 - Question Paper Download PDF June 2025 - Solved Paper + Explanation ...

Intel 8086 Transistor Count: Architecture, Specifications, and Comparison with Other Microprocessors

Intel 8086 Transistor Count: Architecture, Specifications, and Comparison with Other Microprocessors Intel 8086 Transistor Count: Complete Guide with Architecture and Processor Comparison The Intel 8086 microprocessor is one of the most important processors in computer history. Released in 1978 , it introduced the x86 architecture that still influences modern CPUs. One of the most frequently asked questions in computer architecture and microprocessor courses is: How many transistors are present in the Intel 8086? The commonly accepted answer is approximately 29,000 transistors . However, reverse-engineering studies have shown that the actual number of physical transistors is closer to 19,618 , while Intel's published figure includes programmable transistor locations used in ROM and PLA structures. Intel 8086 Transistor Count Metric Value Published transistor count ~29,000 Physical transistor count ~19,618 Release year 1978 Word ...

Orthogonal Time Frequency Space (OTFS) (with MATLAB)

In OTFS (Orthogonal Time Frequency Space) modulation — a scheme designed for high-Doppler and time-varying wireless channels — the terms ISFFT and SFFT are key mathematical transformations used to move between different representation domains. Figure: OTFS block diagram 1. ISFFT — Inverse Symplectic Finite Fourier Transform Purpose: Transforms data symbols from the delay-Doppler domain to the time-frequency domain . \[ X[n, m] = \frac{1}{\sqrt{NM}} \sum_{k=0}^{N-1} \sum_{l=0}^{M-1} x[k, l] \, e^{j2\pi \left( \frac{nk}{N} - \frac{ml}{M} \right)} \] Here, \( N \) is the number of Doppler bins (time slots), and \( M \) is the number of delay bins (subcarriers). The ISFFT maps each data symbol from the delay-Doppler grid (where the channel is sparse and easier to equalize) to the time-frequency grid (where standard multicarrier modulation like OFDM can be applied). 2. SFFT — Symplectic Finite Fourier Transform Purpose: Performs the reverse operation ...

Choke Input Filter Explained

  Choke Input Filter Choke Input Filter A well-designed choke input filter is a type of power supply filter used to smooth the output of a rectifier (like in DC power supplies). It uses an inductor (choke) as the first component right after the rectifier, followed by a capacitor. Basic Structure Rectifier → Choke (L) → Capacitor (C) → Load What Makes It Well-Designed? Critical Inductance is satisfied: The choke must have enough inductance to keep current flowing continuously. This minimum value is called critical inductance. Low ripple output: A good design significantly reduces AC ripple in the DC output. The choke resists sudden changes in current. Proper load current: Works best when the load current is above a certain minimum level. Too light a load results in poor filter...

Q-function in BER vs SNR Calculation

Q-function in BER vs. SNR Calculation In digital communications and signal processing, the Q-function plays a significant role in predicting system reliability. It allows engineers to quantify the probability that Gaussian noise will exceed a specific threshold, causing a bit error. What is the Q-function? The Q-function is a mathematical function representing the tail probability of the standard normal (Gaussian) distribution. It is the complementary cumulative distribution function (CCDF) of a standard Gaussian distribution. Q(x) = (1 / √(2Ï€)) ∫â‚“∞ e^(-t² / 2) dt Q-Function Interactive Simulator Move the slider to see how the "Tail Probability" (the area in red) changes. This area represents the Probability of Error (BER) . Threshold Distance ( x ) — (Simulates Increasing SNR) x = 1.0 Q(x) = 0.1587 ...