I was trying to implement your suggestions in 8PSK demodulation and here is what I got:
clc;
clear all;
close all;
M=16;
k=log2(M);
Nbits=100*k; %Number of bits to transmit
Rb=1e3;
Fc=2e3;
i=sqrt(-1);
msg=randint(1,Nbits,[0 1]);
% Transmitter
%**************************************************
[y, time,Fs,demodu]=bin2Pskconst(msg, M, Rb,0 );
Towpi=2*pi*Fc*time;
In=real
.*cos(Towpi);
Qa=imag
.*sin(Towpi);
Trans=In+i*Qa;
%**************************************************
%Freq Domain plotting
%**************************************************
Pyy=abs(fftshift(fft(Trans)))/length(Trans);
ff=Fs*(-0.5:1/length(time):0.5-1/length(time));
%Reciever
%**************************************************
rI=Trans.*cos(Towpi); %downconverting
rQ=Trans.*sin(Towpi);
Pyy2=abs(fftshift(fft(rI)))/length(rI);
subplot(3,1,1);plot(ff,Pyy,ff,Pyy2);
N = 32; F3dB = .35;
d = fdesign.lowpass('N,F3dB',N,F3dB);
Hbutter = design(d,'butter');
Ap = .5;
setspecs(d,'N,F3dB,Ap',N,F3dB,Ap);
Hcheby1 = design(d,'cheby1');
%hfvt = fvtool([Hbutter,Hcheby1],'Color','white');
%axis([0 .44 -5 .1])
%legend(hfvt,'Butterworth','Chebyshev Type I');
%Filters
BB_rI=filter(Hbutter, rI);
BB_rQ=filter(Hbutter, rQ);
BB_rI2=decimate(BB_rI, 32);
BB_rQ2=decimate(BB_rQ, 32);
subplot(3,1,2);plot(time,BB_rI,time,imag(BB_rQ));
Pbb=abs(fftshift(fft(BB_rI)))/length(rI);
subplot(3,1,3);plot(ff,Pbb);
temp=(BB_rI2+i*BB_rQ2)';
reSig=demodulate(demodu, temp)';
Nerr=biterrfnd(reSig,msg)
function[y, time,Fs,demodu]=bin2Pskconst(x, M, Rb, phaseo )
%x - binary vector
%M - integer constalation - for Mpsk
%y - complex envalop for binary vector x (Works only for MQAM)
%sigSym - Symbol mapping of the binary vector x
k=log2(M);
%phaseo=0; %for debuging
modu = modem.pskmod('M', M, 'PhaseOffset', phaseo,'SymbolOrder', 'Gray', 'InputType', 'Bit');
demodu=modem.pskdemod(modu);
Fs=8*Rb; %Sampling frequency , oversampling factor= 32
Ts=1/Fs; % Sampling Period
Tb=1/Rb; % Bit period
Tsym=k*Tb;
envalope=modulate(modu,x');
y=0;
for n=1:length(envalope)
for tempTime=0:Ts:Tsym-Ts,
y=[y envalope
];
end
end
y=y(1:length
-1);
time=0:Ts:Tsym*length(envalope)-Ts;
function[nErr] = biterrfnd(sig, nsig)
nErr=0;
[m,n] = size(sig);
for i=1:1:m
for j = 1:1:n
nErr = nErr + xor(sig(i,j), nsig(i,j));
end
end
end
Now I get BER equals almost 0.5 and we expect to get zero BER since there is no channel distortion involved.
I believe I have a problem with my code at the filters in the receiver section, if you can kindly look at my code and tell me what I've done wrong it will help me and plenty of others.