# MATLAB Writing mathematical equations in MATLAB

#### EngWiPy

Hello,

I have the attached paper, and I want to write equations 4, 5 and the equation in the first line after equation 5 in MATLAB. I did it as following:

Code:
Np=24;
L=19;
TapsL=[1 19 20];
S=length(TapsL);

Index=zeros(S,1);%Tap Locations
c=zeros(L+1,1);
cHatMP=zeros(L+1,1);
hHatMP=zeros(S,1);%Taps CS Estimates

h=(1/sqrt(2.*(S))).*(randn(S,1)+1i.*randn(S,1));
c(TapsL)=h;

%Channel Estimation
np=(1/sqrt(2*SNR(ii))).*(randn(Np+L,1)+1i.*randn(Np+L,1));
n=(1/sqrt(2*SNR(ii))).*(randn(Nd+L,1)+1i.*randn(Nd+L,1));

xpCP=[xp(end-L+1:end);xp];

yp=filter(c,1,xpCP)+np;

yp(1:L)=[]; At this point we have y=Ac+n

cHatLS=inv(transpose(conj(A))*A)*transpose(conj(A))*yp;%Least square channel estimation

for ss=1:S
max=0;
for pp=1:L+1
if ss>1
set=0;
for mm=1:ss-1
if Index(mm)==pp
set=1;
end
end
if set==0
Proj=(abs(transpose(conj(A(:,pp)))*yp)^2)/norm(A(:,pp))^2;
if Proj>max
max=Proj;
maxIndex=pp;
end
end
else
Proj=(abs(transpose(conj(A(:,pp)))*yp)^2)/norm(A(:,pp))^2;
if Proj>max
max=Proj;
maxIndex=pp;
end
end
end
hHatMP(ss)=transpose(conj(A(:,maxIndex)))*yp/norm(A(:,maxIndex))^2;
Index(ss)=maxIndex;
yp=yp-((transpose(conj(A(:,maxIndex)))*yp*A(:,maxIndex))/norm(A(:,maxIndex))^2);
end

cHatMP(Index)=hHatMP;
but I get unexpected results when using these values. So, I do not know if I am doing it wrongly in MATLAB. Any suggestion, please?

Note: Assume A is given.

Thanks

#### Attachments

• 235.6 KB Views: 158
Related Math Software Workshop News on Phys.org

"Writing mathematical equations in MATLAB"

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving