I have a .mat file which contains a message. I need to decode that signal using QPSK demod using the code below. I need to start work from the "Carrier Demod" section where Tx_Signal is the .mat file.help me extract the no of bits from .mat file.
5 views (last 30 days)
Show older comments
%MY QPSK SYSTEM
clc; clear all; close all;
%% Data Initialization
Num_bits = 10; % Number of bits
P_length = 100; % Half Cycle Sinus length
Fs = 2*P_length;
%% Pulse Generation
t = 0:1/Fs:0.5;
t = t(1:end-1);
Pulse = sin(2*pi*t);
%% Bits Generation
bits = round(rand(1,Num_bits));
figure(1);stem(bits);
title ('Generated Bits');
%% QPSK Mod
a=bits(1:2:end);
b=bits(2:2:end);
qpsk=(-1+2*a)+i*(-1+2*b);
scatterplot(qpsk);
%% Pulse Shaping
Signal = [];
for i = 1:Num_bits/2
Signal = [Signal, qpsk(i)*Pulse];
end
figure (3); stem(Signal);
title ('Modulated Signal')
%% Carrier Mod
fs=10000;
fc=1500;
T=(0:length(Signal)-1)*1/fs;
Real_Signal = real(Signal);
Imag_Signal = imag(Signal);
Re_Sig=Real_Signal.*(sqrt(2)*cos(2*pi*fc*T));
Im_Sig=Imag_Signal.*(-sqrt(2)*sin(2*pi*fc*T));
Tx_Signal=Re_Sig+Im_Sig;
fft_(fs,Tx_Signal)
%% Carrier Demod
Rx_Re_Sig=Tx_Signal.*(sqrt(2)*cos(2*pi*fc*T));
Rx_Im_Sig=Tx_Signal.*(-sqrt(2)*sin(2*pi*fc*T));
fft_(fs,Rx_Re_Sig)
fft_(fs,Rx_Im_Sig)
%% LPF
[B,A]=butter(10,0.2,'Low');
Re_filter=filter(B,A,Rx_Re_Sig);
Im_filter=filter(B,A,Rx_Im_Sig);
fft_(fs,Re_filter)
fft_(fs,Im_filter)
%% Matched Filter Estimation
Rx_Re_MF=conv(Pulse,Re_filter);
Rx_Im_MF=conv(Pulse,Im_filter);
figure(9);plot(Rx_Re_MF);
figure(10);plot(Rx_Im_MF);
%% Sampling of the received signal
Ts = P_length;
[X,Y] = max(abs(Rx_Re_MF(1:1.5*Ts)));
[A,B] = max(abs(Rx_Im_MF(1:1.5*Ts)));
Rx_QPSK_real = [];
Rx_QPSK_imag = [];
for i = 1:Num_bits/2
Rx_QPSK_real = [Rx_QPSK_real, sign(Rx_Re_MF(Y+Ts*(i-1)))];
Rx_QPSK_imag = [Rx_QPSK_imag, sign(Rx_Im_MF(B+Ts*(i-1)))];
end
Rx_QPSK = Rx_QPSK_real+1j*Rx_QPSK_imag;
figure(11);stem (Rx_QPSK);
title ('Demodulated Signal')
%% QPSK Demod
c=real(Rx_QPSK);
d=imag(Rx_QPSK);
Rx_bits=[];
for i=1:Num_bits/2
if c(i)==-1
Rx_bits=[Rx_bits,0];
else
Rx_bits=[Rx_bits,1];
end
if d(i)==-1
Rx_bits=[Rx_bits,0];
else
Rx_bits=[Rx_bits,1];
end
end
figure(12);stem(Rx_bits);
title ('Received Bits')
%% Error Detection
N_Error = nnz(bits-Rx_bits);
0 Comments
Answers (0)
See Also
Categories
Find more on QPSK in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!