Please Solve the Error...if the run the below code..i got one error ..but logically code correct..the error is Matrix dimensions is not match

function [bit_stream ]=msk_demod( signal_ip,f,Tb)
%msk_demod program for minimum shift keying demodulation
% % Detailed explanation goes here
clc;clear all;close all;
s1=0;s2=0;s3=0;s4=0;
d1=0;d2=0;d3=0;d4=0;
bit_odd=0;bit_even=0;
data1=[0 0];
data2=[0 1];
data3=[1 0];
data4=[1 1];
% data=input('Enter the data size 8 bits {Ex:- format [1 1 1 1 0 0 1 0]} ');
% Tb=input('Enter Bit period time from 0 to 1 {Ex:- 0.1}');
% f=input('Enter frequency in Hz from 0 t0 80 {Ex:-7}');
data=[1 0 0 1 1 1 0 0];
Tb=0.1;
f=7;
signal_ip=msk_mod(data,f,Tb,1);
s1=msk_mod(data1,f,Tb,1);
s2=msk_mod(data2,f,Tb,1);
s3=msk_mod(data3,f,Tb,1);
s4=msk_mod(data4,f,Tb,1);
l=length(signal_ip);
n_samp=l/1000;
ind=1;
samp=signal_ip;
for i=1:n_samp
d1=samp(:,(i-1)*1000+1:(i*l)/4).*s1;
d2=samp(:,(i-1)*1000+1:(i*l)/4).*s2;
d3=samp(:,(i-1)*1000+1:(i*l)/4).*s3;
d4=samp(:,(i-1)*1000+1:(i*l)/4).*s4;
d11=0;d22=0;d33=0;d44=0;
for k=1:1000
if (d1(1,k)>0)
d11=d11+1;
end
if (d2(1,k)>0)
d22=d22+1;
end
if (d3(1,k)>0)
d33=d33+1;
end
if (d4(1,k)>0)
d44=d44+1;
end
end
if (d11 > d22) && (d11 > d33) &&(d11 > d44)
bit_odd=0;
bit_even=0;
end
if (d22 > d11) && (d22 > d33) &&(d22 > d44)
bit_odd=0;
bit_even=1;
end
if (d33 > d22) && (d33 > d11) &&(d33 > d44)
bit_odd=1;
bit_even=0;
end
if (d44 > d22) && (d44 > d33) &&(d44 > d11)
bit_odd=1;
bit_even=1;
end
bit_stream(1,ind)=bit_odd;
bit_stream(1,ind+1)=bit_even;
ind=ind+2;
end
bit_stream
end

8 个评论

that is ok, that i alredy there..that modulation code is also k...i want demodulation code and in that i got that error..please run and tell me solution
I did run. The output was
>> msk_demod
Undefined function or variable 'msk_mod'.
Error in msk_demod (line 18)
signal_ip=msk_mod(data,f,Tb,1);
To get any further I would need to have the code for msk_mod
K i put modulation code also..please solve my error
function [ signal ] = msk_mod(bit_stream,f,Tb,Eb)
t=0.001 : .001 : 1;
bit_stream=[1 0 0 1 0 0 1 1];
Eb=1;
nn=length(bit_stream);
amp=sqrt(2*Eb);
Tb=0.001;
f=30;
if (mod(nn,2)~=0)
bit_stream(1,nn+1)=0;
nn=nn+1;
end
N=length(bit_stream);
m_i=zeros(1,N/2);
m_q=zeros(1,N/2);
a=1;
for i=1:1:N/2
if (bit_stream(1,a)==0)
m_i(1,i)=-1;
else
m_i(1,i)=1;
end
a=a+1;
if (bit_stream(1,a)==0)
m_q(1,i)=-1;
else
m_q(1,i)=1;
end
a=a+1;
end
Smsk=zeros(N/2,1000);
for loop =1:N/2
Smsk(loop,:)=(amp*(m_i(1,loop)*sin(2*pi*t/(4*Tb))).*cos(2*pi*f*t)) + (amp*(m_q(1,loop)*cos(2*pi*(t/(4*Tb)))).*sin(2*pi*f*t));
end
signal=column_to_row(Smsk);
end
And i also got one more error while executing one by one line of demodulation of MSK
d1=samp(i,(i-1)*1000+1:(i*l)/4).*s1;
Undefined function or variable 'column_to_row'.
Error in msk_mod (line 37)
signal=column_to_row(Smsk);
Error in msk_demod (line 18)
signal_ip=msk_mod(data,f,Tb,1);
k i will send column_to_row code
function [ output_matrix ] =column_to_row( input_matrix )
% Converts a column matrix to row matrix
% Ex: [1 2 3 4; 2 3 4 5; 9 8 7 6]
% will be converted to [1 2 3 4 2 3 4 5 9 8 7 6]
[a,b]=size(input_matrix);
count=-b;
for i=1:a
count=count+b;
for j=1:b
op(count+j)=input_matrix(i,j);
end
end
output_matrix=op;
end
You could use
reshape(a', 1, numel(a))
instead of your column_to_row function

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Communications Toolbox 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by