Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

QPSK Tx, Rx simulation, for different channels

Status
Not open for further replies.

barznjy

Newbie level 6
Joined
Jan 13, 2013
Messages
13
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,419
Dear Friends,

following is the QPSK Tx, Rx matlab code for different channels.
I have these questions:

First:
I don't understand what is mean by (Correct the phase before detection) (y=conj(h).*y;)? why we need it? how it works? in practical what is that mean?

Second:
In case we have multipath (equalizer), what will change in the system?
I added two path (two different h), but I don't know how to demodulate it.


Third:
Why the contellation diagram of the (slow fading channel) is very strange, since there are a lot of points that cross the origion.

Thank you very much.

clear all; close all; clc;
bits=10^6;
EbN_dB=0:2:16;
EbNo=10.^(EbN_dB/10);
BER=zeros(1,length(EbNo));

for i=1:length(EbN_dB)

% modulation
Ti=(2.*round(randint(1,bits)))-1;
Tq=(2.*round(randint(1,bits)))-1;
x=Ti+1i*Tq;

%generate the channel
h1=1/sqrt(2).*(randn(1,bits)+1i.*rand(1,bits));
h2=1/sqrt(2).*(randn(1,bits)+1i.*rand(1,bits));
n=(1/sqrt(2*EbNo(i)))*(randn(1,bits)+1i*randn(1,bits));

%transmit the signal over flat fading channel
y1=(h1.*x)+n;
y2=(h2.*x)+n;

%Correct the phase before detection
y1=conj(h1).*y1;
y2=conj(h2).*y2;

% demodulation
Ri=sign(real(y));
Rq=sign(imag(y));

% ber calculation
BER1=(bits-sum(Ti==Ri))/bits;
BER2=(bits-sum(Tq==Rq))/bits;
BER(i)=mean([BER1 BER2]);
end

semilogy(EbN_dB, BER,'o-')
axis([0 16 10^-6 1]);
hold on

p=qfunc(sqrt(2*EbNo));
semilogy(EbN_dB,2*p-p.^2,'m-','linewidth',1.0);
legend('Simulated QPSK BER Over Rayleigh Fading','Theoritical QPSK BER Over AWGN');
xlabel('EbNo(dB)')
ylabel('BER')
grid on

% plotting constellation diagram
figure(2)
plot(y,'r.');
hold on
plot(x,'bs');
axis([-2 2 -2 2]);
title('Constellation Plot for QPSK' );
grid;
 

First: \[h^*y=h^*(hx+n)=|h|^2x+h^*n\]. The channel coefficient h is a complex random variable. That is: \[h=|h|e^{j\theta}\]. The phase will cause phase rotation of the signal, and thus must be compensated, otherwise, the detection process fails.

Second: For a multipath channel, the relationship between the output signal and the input signal is convolution with channel. Actually, even in flat fading channel, it is convolution, however with a scaled delta function. In two paths channel, the nth received symbol can be written as \[y_n=h_0x_n+h_1x_{n-1}+z_n\]. Since the channel memory is one, you can transmit blocks of length N with zero before and zero after it as \[[0 x_0 ... x_{N-1} 0]^T\]. You can write the (N+1)-by1 received block as \[\mathbf{y}=\mathbf{H}\mathbf{x}+\mathbf{z}\]. Then you can do linear equalization (like zero forcing ZF or minimum mean squared error MMSE) or nonlinear equalization (like maximum likelihood ML or decision feedback equalizer DFE). For example, for ZF, the output of the equalizer will be \[\mathbf{H}^{-1}\mathbf{y}=\mathbf{x}+\mathbf{H}^{-1}\mathbf{z}\], and then you can do symbol-by-symbol detection. Try to implement this in MATLAB.

Third: Try the constellation after you do the previous step correctly

Thanks
 
I tried to do it like this:

but it doesn't work.


clear all; close all; clc;
bits=10;
EbN_dB=0:2:16;
EbNo=10.^(EbN_dB/10);
BER = zeros(length (bits));
ht = [0.2 0.9 0.3];
for i=1:length(EbN_dB)

% modulation
Ti=(2.*round(randint(1,bits)))-1;
Tq=(2.*round(randint(1,bits)))-1;
x=Ti+1i*Tq;

%generate the channel
h=1/sqrt(2).*(randn(1,bits)+1i.*rand(1,bits));
n=(1/sqrt(2*EbNo(i)))*(randn(1,bits)+1i*randn(1,bits));

%transmit the signal over flat fading channel
y2 = (h.*x);
y=y2+n;

%Correct the phase before detection
y=conj(h).*y;

% getting zero forcing equalization filter cofficients
xM = toeplitz([x zeros(1,length(h)-1) ], [x(1) zeros(1,length(h)-1) ]);
d = zeros(1,length(ht));
d(2) = 1;
c = inv(xM)*d';

yr = c*y2;

% demodulation
Ri=sign(real(yr));
Rq=sign(imag(yr));

% ber calculation
BER1=(bits-sum(Ti==Ri))/bits;
BER2=(bits-sum(Tq==Rq))/bits;
BER(i)=mean([BER1 BER2]);


end

semilogy(EbN_dB, BER,'o-')
axis([0 16 10^-6 1]);
hold on

p=qfunc(sqrt(2*EbNo));
semilogy(EbN_dB,2*p-p.^2,'m-','linewidth',1.0);
legend('Simulated QPSK BER Over multi-path Rayleigh Fading','Theoritical QPSK BER Over AWGN');
xlabel('EbNo(dB)')
ylabel('BER')
grid on

% plotting constellation diagram
figure(2)
plot(y,'r.');
hold on
plot(x,'bs');
axis([-2 2 -2 2]);
title('Constellation Plot for QPSK' );
grid;
 

See below. Try to fix them, and tell me what happens.

I tried to do it like this:

but it doesn't work.


clear all; close all; clc;
bits=10;
EbN_dB=0:2:16;
EbNo=10.^(EbN_dB/10);
BER = zeros(length (bits));
ht = [0.2 0.9 0.3];
for i=1:length(EbN_dB)

% modulation
Ti=(2.*round(randint(1,bits)))-1;
Tq=(2.*round(randint(1,bits)))-1;
x=Ti+1i*Tq;

%generate the channel
h=1/sqrt(2).*(randn(1,bits)+1i.*rand(1,bits));This is the way of generating a channel in flat fading. In frequency selective channel you will have a channel with at least two taps that are constant over a block of data. define h=1/sqrt(2*L).*(randn(L,1)+1i.*randn(L,1)) where L is the channel length. Or if you have a static channel ht (of length 3), that is fine, but this is not a fading channel
n=(1/sqrt(2*EbNo(i)))*(randn(1,bits)+1i*randn(1,bits));

%transmit the signal over flat fading channel
y2 = (h.*x);%This is true for flat fading. For frequency selective channel, use the command y=filter(h,1,x) to realize the convolution
y=y2+n;

%Correct the phase before detection
y=conj(h).*y;%No need for this

% getting zero forcing equalization filter cofficients
xM = toeplitz([x zeros(1,length(h)-1) ], [x(1) zeros(1,length(h)-1) ]);%The toeplitz matrix elements are the channel coefficients, not the signal. If we know the signal there is no need for this whole process.
d = zeros(1,length(ht));%What is this?
d(2) = 1;What is this?
c = inv(xM)*d';What is this?

yr = c*y2;

% demodulation
Ri=sign(real(yr));
Rq=sign(imag(yr));

% ber calculation
BER1=(bits-sum(Ti==Ri))/bits;
BER2=(bits-sum(Tq==Rq))/bits;
BER(i)=mean([BER1 BER2]);


end

semilogy(EbN_dB, BER,'o-')
axis([0 16 10^-6 1]);
hold on

p=qfunc(sqrt(2*EbNo));
semilogy(EbN_dB,2*p-p.^2,'m-','linewidth',1.0);
legend('Simulated QPSK BER Over multi-path Rayleigh Fading','Theoritical QPSK BER Over AWGN');
xlabel('EbNo(dB)')
ylabel('BER')
grid on

% plotting constellation diagram
figure(2)
plot(y,'r.');
hold on
plot(x,'bs');
axis([-2 2 -2 2]);
title('Constellation Plot for QPSK' );
grid;
 

Hi,

I don't know if its still correct or not.

clear all; close all; clc;
bits=10;
EbN_dB=0:2:16;
EbNo=10.^(EbN_dB/10);
BER = zeros(length (bits));
L = 3;

for i=1:length(EbN_dB)

% modulation
Ti=(2.*round(randint(1,bits)))-1;
Tq=(2.*round(randint(1,bits)))-1;
x=Ti+1i*Tq;

%generate the channel

h=1/sqrt(2*L).*(randn(L,1)+1i.*randn(L,1));

n=(1/sqrt(2*EbNo(i)))*(randn(1,bits)+1i*randn(1,bits));

%transmit the signal over frequency selective channel

y=filter(h,1,x);

y1=y+n;

% getting zero forcing equalization filter cofficients

xM = toeplitz([h zeros(1,length(bits)-1) ], [h zeros(1,length(bits)-1) ]);


% demodulation

yr = inv(xM')*y1;

Ri=sign(real(yr));
Rq=sign(imag(yr));

% ber calculation
BER1=(bits-sum(Ti==Ri))/bits;
BER2=(bits-sum(Tq==Rq))/bits;
BER(i)=mean([BER1 BER2]);


end

semilogy(EbN_dB, BER,'o-')
axis([0 16 10^-6 1]);
hold on

p=qfunc(sqrt(2*EbNo));
semilogy(EbN_dB,2*p-p.^2,'m-','linewidth',1.0);
legend('Simulated QPSK BER Over multi-path Rayleigh Fading','Theoritical QPSK BER Over AWGN');
xlabel('EbNo(dB)')
ylabel('BER')
grid on

% plotting constellation diagram
figure(2)
plot(y,'r.');
hold on
plot(x,'bs');
axis([-2 2 -2 2]);
title('Constellation Plot for QPSK' );
grid;
 

See the code below for BPSK signaling with MMSE equalizer. Try to understand it, and extend it to QPSK. An MMSE equalizer is an equalizer that minimizes the mean squared error
\[\mathbb{E}\{|\mathbf{x}-\mathbf{W}\mathbf{y}|^2\}\]
which yields to
\[\mathbf{W}=\mathbf{H}^H(\mathbf{H}^H\mathbf{H}+N_0\mathbf{I}_N)^{-1}\]
Code:
clear all;
clc;

SNRdB=0:20;
SNR=10.^(SNRdB./10);

N=128;
L=3;
Nerr=100;

nErr=zeros(1,length(SNR));
Count=zeros(1,length(SNR));


for ii=1:length(SNR)
    while nErr(ii)<=Nerr
        Count(ii)=Count(ii)+N;
        
        b=rand(N,1)>0.5;
        x=2.*b-1;
        
        h=1/sqrt(2*(L+1)).*(randn(L+1,1)+1i.*randn(L+1,1));
        c=[h;zeros(N-L-1,1)];
        r=[h(1);zeros(N-1,1)];
        H=toeplitz(c,r);
        
        n=1/sqrt(2*SNR(ii)).*(randn(N,1)+1i.*randn(N,1));
        
        y=filter(h,1,x)+n;
        
        yEq=conj(transpose(H))*inv(H*conj(transpose(H))+(1/SNR(ii))*eye(N))*y;
        
%         yEq(end-L+1:end)=[];
        
        bHat=real(yEq)>0;
        
        nErr(ii)=nErr(ii)+sum(bHat~=b);
    end
end

semilogy(SNRdB,nErr./Count);
 

Hi,
what is the difference between EbNo and snr?
which one is commonly use?
what is the equation of awgn noise?

as I know ebno is the enery per bit, so in bpsk ebno and snr are the same right? and snr is signal energy (symbol energy).
but for qpsk we need to divide by 2, and 8psk divid by 3, right? this is in case when we need BER calculation, and if we need to calculate SER we don't need this division, right?

here is how I get the equation of noise:

snr=10^((-0.1)*snr_dB)
sd=sqrt((1/4)*snr);
noise_awgn = sd*(randn(1)+1i*randn(1));
 

In MATLAB code, you need SNR per symbol, since you are transmitting symbols. I think the best way to do this, is to consider SNR as the SNR per bit \[\gamma_b\], and then define SNR per symbol to be \[\gamma_s=\gamma_b\log_2M\], where M is the constellation size, and at the end plot the BER versus SNR per bit.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top