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.

question about this code mimo alamouti 2x2

Status
Not open for further replies.

blue_sky_2882

Newbie level 3
Joined
Sep 24, 2012
Messages
4
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,427
hello my friends

I want to use alamouti scheme in a channel with ISI . then I should use this program for getting out put of a rayligh channel with ISI



%************************************************************************************

function OutSignal = Channel(TimeSignal,clipcompress,SNR,Multipath)
% CHANNEL Applies a channel model to the waveform including, noise, multipath & clipping.
%
% OutSignal = channel(TimeSignal,clipcompress,SNR,Multipath)
%
% The model is the simulate some of the effects of a radio channel. For this reason,
% the effects are applied in the following order :
% 1. Clipping : Effect from the output power amplifier.
% 2. Noise : Thermal noise due to the channel.
% 3. Multipath : Channel effect at the receiver.
%
% INPUTS:
% TimeSignal : Time waveform of signal to apply the channel to.
% clipcompress : Amount of clipping to apply to the signal, in dB
% Peak Power of original signal / Peak Power after clipping.
% if no clipping is needed choos clipcompress = 0.
% SNR : SNR of the transmitted signal, in dB,
% RMS power of original signal / RMS power of noise to be added.
% if no noise is needed choose SNR >= 300.
% Multipath : This is a vector of the magnitude and delay for each reflection.
% This is a coefficient vector for modelling the multipath with an
% FIR filter. The first coefficient must be 1 if a direct signal is
% needed.
% For Example : for reflections at sample times : 5 & 7 with magnitude
% of 50% & 30% respectively of the direct signal :
% Multipath = [1 0 0 0 0 0.5 0 0.3]
% If no multipath effect is needed make 'Multipath' = []
% OUTPUTS:
% OutSignal : Output signal after the model.

%================================
%Clip the signal
%================================
if clipcompress ~= 0,
MaxAmp = (10^(0-(clipcompress/20)))*max(TimeSignal);
TimeSignal(TimeSignal>=MaxAmp)=ones(1,length(find(TimeSignal>=MaxAmp)))*MaxAmp;
TimeSignal(TimeSignal<=(-MaxAmp))=ones(1,length(find(TimeSignal<=(-MaxAmp))))*(-MaxAmp);
% PeaktoRms = 10*log10(max(TimeSignal.^2)/(std(TimeSignal)^2));
end
%================================
%Add noise
%================================
if SNR < 300,

SigPow = std(TimeSignal); %find the signal power
NoiseFac = 10^(0-(SNR/20));
TimeSignal = TimeSignal + randn(1,length(TimeSignal))*SigPow*NoiseFac;
end

%================================
%Add multipath
%================================
if ~isempty(Multipath)
TimeSignal = filter(Multipath,1,TimeSignal); %add multi path to the signal
end

OutSignal = TimeSignal;

%************************************************************************************





Now I have this codes about alamouti scheme :



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% ALAMOUTI CODE for 2 transmitters and 2 receivers %%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all;
close all;
M=16;
N = 10^6; % number of bits or symbols
snr=linspace(0,20,21);
h11 = 1/sqrt(2)*(randn(1,N/2) + 1i*randn(1,N/2));
h12 = 1/sqrt(2)*(randn(1,N/2) + 1i*randn(1,N/2));
h21 = 1/sqrt(2)*(randn(1,N/2) + 1i*randn(1,N/2));
h22 = 1/sqrt(2)*(randn(1,N/2) + 1i*randn(1,N/2));
h=[h11;h12;h21;h22];
h = reshape(h,2,N);
HEq = zeros(2,2*N);
HEq:),(1:4:end)) = h:),(1:2:end));
HEq:),(2:4:end)) = h:),(2:2:end));
HEq:),(3:4:end)) = flipud(h:),(1:2:end)));
HEq:),(4:4:end)) = flipud(h:),(2:2:end)));
HEq(2,:)=conj(HEq(2,:));
HEq(2,(3:4:end))=-1*HEq(2,(3:4:end));
HEq(2,(4:4:end))=-1*HEq(2,(4:4:end));
HEq = reshape(HEq,4,N);
hEq = zeros(2,N);
hEq:),(1:2:end)) = reshape(h:),(1:2:end)),2,N/2); % [h1 0 ... ; h2 0...]
hEq:),(2:2:end)) = kron(ones(1,N/2),[1;-1]).*flipud(reshape(h:),(1:2:end)),2,N/2)); % [h1 h2 ... ; h2 -h1 ...]
hEq(1,:) = conj(hEq(1,:)); % [h1* h2* ... ; h2 -h1 .... ]
hEqPower3 = sum(hEq.*conj(hEq),1);% mod(h1)^2+mod(h2)^2
hEq1 = zeros(2,N);
hEq1:),(1:2:end)) = reshape(h:),(2:2:end)),2,N/2); % [h1 0 ... ; h2 0...]
hEq1:),(2:2:end)) = kron(ones(1,N/2),[1;-1]).*flipud(reshape(h:),(2:2:end)),2,N/2)); % [h1 h2 ... ; h2 -h1 ...]
hEq1(1,:) = conj(hEq1(1,:)); % [h3* h4* ... ; h4 -h3 .... ]
hEqPower1 = sum(hEq1.*conj(hEq1),1);% mod(h3)^2+mod(h4)^2
hEqPower3=hEqPower3+hEqPower1;
hEqPower=zeros(1,N/2);
hEqPower=hEqPower3:),(1:2:end));
% Transmitter
x = randint(N,1,M);
x5=reshape(x,1,N);
y3=modulate(modem.qammod(M),x);
y3=reshape(y3,1,N);
y5 = zeros(2,N);
y5:),1:2:end) = reshape(y3,2,N/2); % [x1 x2; ...]
y5:),2:2:end) =(kron(ones(1,N/2),[-1;1]).*flipud(reshape(conj(y3),2,N/2)));% [-x2* x1*; ....]
h1=h:),(1:2:end));
h2=h:),(2:2:end));
H1 = kron(reshape(h1,2,N/2),ones(1,2));
H2 = kron(reshape(h2,2,N/2),ones(1,2));
ser=zeros(1,length(snr));
tg1=sum(H1.*y5,1);
tg2=sum(H2.*y5,1);

hEqPower6=[hEqPower;hEqPower];
HEq1=conj(HEq);
for i = 1:length(snr)
N11=1/sqrt(2)*(randn(1,N/2)+1i*randn(1,N/2));
N12=1/sqrt(2)*(randn(1,N/2)+1i*randn(1,N/2));
N1=[N11;N12];
N1=reshape(N1,1,N);
y1=tg1+10^(-(snr(i)-10*log10(20))/20)*N1;
N11=1/sqrt(2)*(randn(1,N/2)+1i*randn(1,N/2));
N12=1/sqrt(2)*(randn(1,N/2)+1i*randn(1,N/2));
N1=[N11;N12];
N1=reshape(N1,1,N);
y2=tg2+10^(-(snr(i)-10*log10(20))/20)*N1;
y1=reshape(y1,2,N/2);
y2=reshape(y2,2,N/2);
y=[y1;y2];
y((2:2:end),:)=conj(y((2:2:end),:));
y9=zeros(4,2*N);
y9=[y;y];
y9=reshape(y9,4,N);
some=sum(y9.*HEq1,1);
some=reshape(some,2,N/2)./sqrt(hEqPower6);
dd3=[];
for g=1:2
some1=some(g,:);
j0=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),0));
j1=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),1));
j2=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),2));
j3=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),3));
j4=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),4));
j5=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),5));
j6=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),6));
j7=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),7));
j8=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),8));
j9=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),9));
j10=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),10));
j11=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),11));
j12=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),12));
j13=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),13));
j14=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),14));
j15=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),15));
rVec = [j0;j1;j2;j3;j4;j5;j6;j7;j8;j9;j10;j11;j12;j13;j14;j15];
[jj, dd] = min(rVec,[],1);
dd3=[dd3;dd];
dd=[];
end
dd3=dd3-1;
dd3=reshape(dd3,1,N);
[num ty]=symerr(x5,dd3);
ser(i)=ty;
dd3=[];
y=[];
end
semilogy(snr,ser,'g-+','linewidth',1);
grid on;hold on;
title('Alamouti nTx=2, nRx=2, for 16-QAM','Color','k','FontSize',13);
legend('sim (nTx=2, nRx=2, Alamouti(16-QAM))','location','southwest');
xlabel('SNR(dB) ---->','Color','k','FontSize',11);Ylabel('Symbol Error Rate ---->','Color','k','FontSize',11);
Email ThisBlogThis!Share to TwitterShare to Facebook
%===================================================================================

in last program in lines that I highlighted them , the programmer use " .*" but because my channel is frequency selective, I should use the channel function that I speake about at first... but when I change it and use the channel function instead of ".*" my BER/SNR an also SER/SNR is wrong!!

can any body help me? and say where I am wrong? I show U the second code after my changes at last...




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% ALAMOUTI CODE for 2 transmitters and 2 receivers %%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all;
close all;
M=16;
N = 10^4; % number of bits or symbols
snr=linspace(0,20,21);
h11 = 1/sqrt(2)*(randn(1,N/2) + 1i*randn(1,N/2));
h12 = 1/sqrt(2)*(randn(1,N/2) + 1i*randn(1,N/2));
h21 = 1/sqrt(2)*(randn(1,N/2) + 1i*randn(1,N/2));
h22 = 1/sqrt(2)*(randn(1,N/2) + 1i*randn(1,N/2));
h=[h11;h12;h21;h22];
h = reshape(h,2,N);
HEq = zeros(2,2*N);
HEq:),(1:4:end)) = h:),(1:2:end));
HEq:),(2:4:end)) = h:),(2:2:end));
HEq:),(3:4:end)) = flipud(h:),(1:2:end)));
HEq:),(4:4:end)) = flipud(h:),(2:2:end)));
HEq(2,:)=conj(HEq(2,:));
HEq(2,(3:4:end))=-1*HEq(2,(3:4:end));
HEq(2,(4:4:end))=-1*HEq(2,(4:4:end));
HEq = reshape(HEq,4,N);
hEq = zeros(2,N);
hEq:),(1:2:end)) = reshape(h:),(1:2:end)),2,N/2); % [h1 0 ... ; h2 0...]
hEq:),(2:2:end)) = kron(ones(1,N/2),[1;-1]).*flipud(reshape(h:),(1:2:end)),2,N/2)); % [h1 h2 ... ; h2 -h1 ...]
hEq(1,:) = conj(hEq(1,:)); % [h1* h2* ... ; h2 -h1 .... ]
hEqPower3 = sum(hEq.*conj(hEq),1);% mod(h1)^2+mod(h2)^2
hEq1 = zeros(2,N);
hEq1:),(1:2:end)) = reshape(h:),(2:2:end)),2,N/2); % [h1 0 ... ; h2 0...]
hEq1:),(2:2:end)) = kron(ones(1,N/2),[1;-1]).*flipud(reshape(h:),(2:2:end)),2,N/2)); % [h1 h2 ... ; h2 -h1 ...]
hEq1(1,:) = conj(hEq1(1,:)); % [h3* h4* ... ; h4 -h3 .... ]
hEqPower1 = sum(hEq1.*conj(hEq1),1);% mod(h3)^2+mod(h4)^2
hEqPower3=hEqPower3+hEqPower1;
hEqPower=zeros(1,N/2);
hEqPower=hEqPower3:),(1:2:end));
% Transmitter
x = randint(N,1,M);
x5=reshape(x,1,N);
y3=modulate(modem.qammod(M),x);
y3=reshape(y3,1,N);
y5 = zeros(2,N);
y5:),1:2:end) = reshape(y3,2,N/2); % [x1 x2; ...]
y5:),2:2:end) =(kron(ones(1,N/2),[-1;1]).*flipud(reshape(conj(y3),2,N/2)));% [-x2* x1*; ....]
h1=h:),(1:2:end));
h2=h:),(2:2:end));
H1 = kron(reshape(h1,2,N/2),ones(1,2));
H2 = kron(reshape(h2,2,N/2),ones(1,2));
ser=zeros(1,length(snr));


OutSignal1 = channel(y5(1,:),0,0,H1(1,:))
OutSignal2 = channel(y5(2,:),0,0,H1(2,:))

tg1=OutSignal1+OutSignal2;

OutSignal11 = channel(y5(1,:),0,0,H2(1,:))
OutSignal22 = channel(y5(2,:),0,0,H2(2,:))

tg2=OutSignal11+OutSignal22;



hEqPower6=[hEqPower;hEqPower];
HEq1=conj(HEq);
for i = 1:length(snr)
N11=1/sqrt(2)*(randn(1,N/2)+1i*randn(1,N/2));
N12=1/sqrt(2)*(randn(1,N/2)+1i*randn(1,N/2));
N1=[N11;N12];
N1=reshape(N1,1,N);
y1=tg1+10^(-(snr(i)-10*log10(20))/20)*N1;
N11=1/sqrt(2)*(randn(1,N/2)+1i*randn(1,N/2));
N12=1/sqrt(2)*(randn(1,N/2)+1i*randn(1,N/2));
N1=[N11;N12];
N1=reshape(N1,1,N);
y2=tg2+10^(-(snr(i)-10*log10(20))/20)*N1;
y1=reshape(y1,2,N/2);
y2=reshape(y2,2,N/2);
y=[y1;y2];
y((2:2:end),:)=conj(y((2:2:end),:));
y9=zeros(4,2*N);
y9=[y;y];
y9=reshape(y9,4,N);
some=sum(y9.*HEq1,1);
some=reshape(some,2,N/2)./sqrt(hEqPower6);
dd3=[];
for g=1:2
some1=some(g,:);
j0=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),0));
j1=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),1));
j2=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),2));
j3=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),3));
j4=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),4));
j5=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),5));
j6=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),6));
j7=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),7));
j8=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),8));
j9=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),9));
j10=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),10));
j11=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),11));
j12=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),12));
j13=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),13));
j14=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),14));
j15=abs(some1-sqrt(hEqPower).*modulate(modem.qammod(M),15));
rVec = [j0;j1;j2;j3;j4;j5;j6;j7;j8;j9;j10;j11;j12;j13;j14;j15];
[jj, dd] = min(rVec,[],1);
dd3=[dd3;dd];
dd=[];
end
dd3=dd3-1;
dd3=reshape(dd3,1,N);
[num ty]=symerr(x5,dd3);
ser(i)=ty;
dd3=[];
y=[];
end
semilogy(snr,ser,'g-+','linewidth',1);
grid on;hold on;
title('Alamouti nTx=2, nRx=2, for 16-QAM','Color','k','FontSize',13);
legend('sim (nTx=2, nRx=2, Alamouti(16-QAM))','location','southwest');
xlabel('SNR(dB) ---->','Color','k','FontSize',11);Ylabel('Symbol Error Rate ---->','Color','k','FontSize',11);
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top