Filter löschen
Filter löschen

Packet generation in simulink using MATLAB script

26 Ansichten (letzte 30 Tage)
Fumihiko Sato
Fumihiko Sato am 17 Jul. 2024 um 7:35
Beantwortet: Zinea am 18 Jul. 2024 um 10:50
Hello,
I have a question about wireless communication.
I want to use a protocol that generates packets (bit streams) and then passes the data to Simulink as a MATLAB script for further processing. The signal flow would be as follows:
  1. Bit stream (from the desire protocol)
  2. Modulation (DBPSK)
  3. Tx filtering (RRC Filter)
  4. Upconvert from baseband (BB) to RF
  5. Send over an AWGN channel
  6. Downconvert from RF to BB
  7. Automatic Gain Control (AGC)
  8. RX filtering (RRC Filter)
  9. Demodulation
  10. Bit stream
Is this possible?
My goal is to evaluate the performance of the designed transceiver by analyzing the Packet Error Rate (PER). I need to consider the PER on a frame basis, rather than just bit by bit.
Thank you!
Fumihiko Sato

Antworten (1)

Zinea
Zinea am 18 Jul. 2024 um 10:50
Here is the outline of the procedure along with documentation links to generate the bitstream using a protocol and then passing this to Simulink for further analysis:
  1. Generate Protocol frame: You need to create a function that generates a protocol frame with a header and a payload. You may use any other protocol too.
function bitStream = generateProtocolFrame(frameNum, frameSize)
headerSize = 16; % Number of bits in the header
payloadSize = frameSize - headerSize; % Number of bits in the payload
% Header: Frame number (16 bits)
header = de2bi(frameNum, headerSize, 'left-msb')';
% Payload: Random data bits
payload = randi([0 1], payloadSize, 1);
% Combine header and payload
bitStream = [header; payload];
end
2. Modulation: For DBPSK modulation, use ‘dpskmod’ function in MATLAB. Documentation link: https://www.mathworks.com/help/comm/ref/comm.dpskmodulator-system-object.html
txSignal = dpskmod(txBits, 2);
3. Tx filtering (RRC Filter): Design and apply an RRC filter using ‘rcosdeign’. Documentation link: https://www.mathworks.com/help/signal/ref/rcosdesign.html
rolloff = 0.25; % Roll-off factor
span = 10; % Filter span in symbols
sps = 4; % Samples per symbol
rrcFilter = rcosdesign(rolloff, span, sps);
txSignalFiltered = filter(rrcFilter, 1, txSignalUpsampled);
4. Upconvert from Baseband (BB) to RF: Upconvert the signal to RF using a carrier frequency ‘fc’.
fc = 1e3; % Carrier frequency
fs = 10e3; % Sampling frequency
t = (0:length(txSignalFiltered)-1)'/fs;
txSignalRF = real(txSignalFiltered .* exp(1i*2*pi*fc*t));
5. Send over an AWGN Channel: Pass the signal through an AWGN channel using ‘awgn’. Documentation link: https://www.mathworks.com/help/comm/ref/awgn.html
SNR = 10; % Signal-to-Noise Ratio in dB
rxSignalRF = awgn(txSignalRF, SNR, 'measured');
6. Downconvert from RF to BB: Downconvert the received RF signal back to baseband.
rxSignalBB = rxSignalRF .* exp(-1i*2*pi*fc*t);
7. Automatic Gain Control(AGC): Normalize the received signal.
rxSignalAGC = rxSignalBB / max(abs(rxSignalBB));
8. RX Filtering (RRC filter): Apply the same RRC filter to the received signal.
rxSignalFiltered = filter(rrcFilter, 1, rxSignalAGC);
9. Demodulation: Demodulate the signal using ‘dpskdemod’. Documentation link: https://ww.mathworks.com/help/comm/ref/dpskdemod.html
rxBits = dpskdemod(rxSignalDownsampled, 2);
10. Calculate the PER: Compare the transmitted and received bits and calculate the PER.
numErrors = sum(txBits ~= rxBits);
PER = numErrors / (numFrames * frameSize);
disp(['Packet Error Rate (PER): ', num2str(PER)]);
11. Pass data to Simulink: Pass the bitstream data to Simulink for further processing. Documentation link: https://www.mathworks.com/help/simulink/slref/sim.html
bitstreamData = bitstreamData';
simOut = sim('bitstream_processing', 'SimulationMode', 'normal', ...
'SaveOutput', 'on', 'OutputSaveName', 'yout', ...
'SrcWorkspace', 'current');
Hope it helps!
Best,
Zinea

Produkte


Version

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by