Filter löschen
Filter löschen

How to generate a BPSK signal

47 Ansichten (letzte 30 Tage)
ATHIRA VIJAY
ATHIRA VIJAY am 8 Feb. 2016
bpsk signal with carrier frequency 20Mhz,bandwidth 2MHz and which is sampled at 80MHz

Akzeptierte Antwort

Chandresh Vora
Chandresh Vora am 13 Jul. 2021
% Generate BPSK signal with carrier frequency 20Mhz, bandwidth 2MHz
% and which is sampled at 80MHz
% Set up
% Specified parameters
M = 2; % Modulation order (BPSK)
Fc = 20e6; % Carrier frequency, Hz
Fb = 2e6; % Bit (baud) rate, bps OR bandwidth, Hz. For BPSK, bandwidth = bit rate
Fs = 4*Fc; % Sampling frequency, Hz
% Assumed & derived parameters
nData = 1000; % Number of bits
Ts = 1/Fs; % Sample time, sec
Td = nData/Fb; % Time duration, sec
spb = Fs/Fb; % Samples per bit
fSpan = 4; % Filter span in symbols
% Visualize the spectrum of baseband BPSK & modulated carrier
specAn1 = dsp.SpectrumAnalyzer("SampleRate", Fs, "Method","Filter bank",...
"AveragingMethod","Exponential","Title", "Pulse Shaped Baseband BPSK");
specAn2 = dsp.SpectrumAnalyzer("SampleRate", Fs, "Method","Filter bank",...
"AveragingMethod","Exponential","Title", "BPSK Modulated Carrier");
% Transmitter
% Generate random data bits
data = randi([0 M-1],nData,1);
% Modulate the data
modData = real(pskmod(data,M));
% Pulse shape & upsample to match carrier's sampling rate. Pulse shaping is
% used to reduce intersymbol interference and to reduce spectral width of
% the modulated signal.
txFilter = comm.RaisedCosineTransmitFilter("FilterSpanInSymbols",fSpan,...
"OutputSamplesPerSymbol",spb);
txfilterOut = txFilter(modData);
specAn1(txfilterOut);
% Multiply modulated & pulse shaped signal with carrier
sine = dsp.SineWave("Frequency",Fc,"SampleRate",Fs,"ComplexOutput",false,...
"SamplesPerFrame",Td/Ts);
carrier = sine();
txSignal = txfilterOut .* carrier;
specAn2((txSignal));
% Receiver
% Multiply received signal with carrier
rxSignal = txSignal .* conj(carrier);
% Low pass match filter to account for pulse shaping
rxFilter = comm.RaisedCosineReceiveFilter("FilterSpanInSymbols",fSpan,...
"InputSamplesPerSymbol",spb,"DecimationFactor",spb);
rxFilterOut = rxFilter(rxSignal);
% Demodulate
dataOut = pskdemod(rxFilterOut,M);
% Each of the Tx and Rx filters introduces a delay of fSpan/2 symbols, for
% a total delay of fSpan symbols (= bits for BPSK). Delay received bits by
% fDelay for accurate comparison with transmitted bits.
fDelay = fSpan;
[numErr, ber] = biterr(data(1:nData-fDelay),dataOut(fDelay+1:nData))
  1 Kommentar
Idin Motedayen-Aval
Idin Motedayen-Aval am 30 Mai 2024
Bearbeitet: Idin Motedayen-Aval am 30 Mai 2024
Note: dsp.SpectrumAnalyzer will be removed in a future release (it's on a deprecation path).
You can simply replace "dsp.SpectrumAnalyzer" with "spectrumAnalyzer" in the above code, and everything will work as expected.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

John BG
John BG am 8 Feb. 2016
You can do it manually, starting from scratch as in the MATLAB examples found when searching 'signals generation' > Waveform Generation
OR
you can use already defined classes to build analogue and digitally modulated signals, search for 'Digital Baseband Modulation': MATLAB help example code
% Create binary data symbols
data = randi([0 1], 96, 1);
% Create a BPSK modulator System object
hModulator = comm.BPSKModulator;
% Change the phase offset to pi/16
hModulator.PhaseOffset = pi/16;
% Modulate and plot the data
modData = step(hModulator, data);
scatterplot(modData)
When building communication systems SIMULINK is really useful. Open Simulink from MATLAB with command 'simulink'.
SIMULINK has blocks already defined for any of the basic digital modulations. In MATLAB help search for 'PM Modulation'.
In SIMULINK open the Communications System Toolbox > Digital Baseband Modulation > PM: take your pick of BPSK modulation.
Even more useful is the SIMULINK set of related examples, among them, you can start for instance with commandapteq.m
Search with this demo name to directly open the example. In this example turning QPSK into BPSK is easy.
If you find this answer helpful, please click on the thumbs-up vote link above, thanks in advance
John

aaniket
aaniket am 29 Okt. 2023
% Generate BPSK signal with carrier frequency 20Mhz, bandwidth 2MHz
% and which is sampled at 80MHz
% Set up
% Specified parameters
M = 2; % Modulation order (BPSK)
Fc = 20e6; % Carrier frequency, Hz
Fb = 2e6; % Bit (baud) rate, bps OR bandwidth, Hz. For BPSK, bandwidth = bit rate
Fs = 4*Fc; % Sampling frequency, Hz
% Assumed & derived parameters
nData = 1000; % Number of bits
Ts = 1/Fs; % Sample time, sec
Td = nData/Fb; % Time duration, sec
spb = Fs/Fb; % Samples per bit
fSpan = 4; % Filter span in symbols
% Visualize the spectrum of baseband BPSK & modulated carrier
specAn1 = dsp.SpectrumAnalyzer("SampleRate", Fs, "Method","Filter bank",...
"AveragingMethod","Exponential","Title", "Pulse Shaped Baseband BPSK");
specAn2 = dsp.SpectrumAnalyzer("SampleRate", Fs, "Method","Filter bank",...
"AveragingMethod","Exponential","Title", "BPSK Modulated Carrier");
% Transmitter
% Generate random data bits
data = randi([0 M-1],nData,1);
% Modulate the data
modData = real(pskmod(data,M));
% Pulse shape & upsample to match carrier's sampling rate. Pulse shaping is
% used to reduce intersymbol interference and to reduce spectral width of
% the modulated signal.
txFilter = comm.RaisedCosineTransmitFilter("FilterSpanInSymbols",fSpan,...
"OutputSamplesPerSymbol",spb);
txfilterOut = txFilter(modData);
specAn1(txfilterOut);
% Multiply modulated & pulse shaped signal with carrier
sine = dsp.SineWave("Frequency",Fc,"SampleRate",Fs,"ComplexOutput",false,...
"SamplesPerFrame",Td/Ts);
carrier = sine();
txSignal = txfilterOut .* carrier;
specAn2((txSignal));
% Receiver
% Multiply received signal with carrier
rxSignal = txSignal .* conj(carrier);
% Low pass match filter to account for pulse shaping
rxFilter = comm.RaisedCosineReceiveFilter("FilterSpanInSymbols",fSpan,...
"InputSamplesPerSymbol",spb,"DecimationFactor",spb);
rxFilterOut = rxFilter(rxSignal);
% Demodulate
dataOut = pskdemod(rxFilterOut,M);
% Each of the Tx and Rx filters introduces a delay of fSpan/2 symbols, for
% a total delay of fSpan symbols (= bits for BPSK). Delay received bits by
% fDelay for accurate comparison with transmitted bits.
fDelay = fSpan;
[numErr, ber] = biterr(data(1:nData-fDelay),dataOut(fDelay+1:nData))

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by