Shruti01
Member level 3
- Joined
- Apr 14, 2010
- Messages
- 67
- Helped
- 3
- Reputation
- 6
- Reaction score
- 3
- Trophy points
- 1,288
- Location
- Mumbai, India
- Activity points
- 1,941
hello all,
I have written a code for qpsk modulation in matlab. My code is as follows:
clc;
close all;
d = [0 1 1 1 0 1 0 0 1 0] % Data sequence
b = 2*d-1 % Convert unipolar to bipolar
Tb = 1 % Bit duration
fc = 3/Tb % Carrier frequency
Es = Tb/2 % This will result into unit amplitude waveforms
t = linspace(0, 10, 1000); % Discrete time samples between 0 and 10*Tb(1000 samples)
N = length(t) % Number of samples
Nsb = N/length(d) % Number of samples per bit
dd = repmat(d', 1, Nsb); % Replicate each bit Nsb times
bb = repmat(b', 1, Nsb);
dw = dd'; % Represent dw into a column vector(column by column)
dw = dw)'; % Represent dw into a row vector(row by row)
bw = bb'; % Represent bw into a column vector(column by column)
bw = bw)'; % Data sequence samples
o = b(1:2:end) %separating odd bits
e = b(2:2:end) %separating even bits
oo = repmat(o', 1, Nsb)
ee = repmat(e', 1, Nsb)
ow = oo'
ow = ow)'
ew = ee'
ew = ew)'
inPhaseOsc = 1/sqrt(2*Es/Tb)*cos(2*pi*fc*t)
quadPhaseOsc = 1/sqrt(2*Es/Tb)*sin(2*pi*fc*t)
qpskModulated = ow.*quadPhaseOsc + ew.*inPhaseOsc;
% Plotting the waveforms
subplot(4,1,1);
plot(t,dw);axis([0 10 -1.5 1.5])
subplot(4,1,2);
plot(t,bw);axis([0 10 -1.5 1.5])
subplot(4,1,3);
plot(t,inPhaseOsc);axis([0 10 -1.5 1.5])
subplot(4,1,4);
plot(t,quadPhaseOsc);axis([0 10 -1.5 1.5])
subplot(4,1,5);
plot(t,qpskModulated);axis([0 10 -1.5 1.5])
When I run the program, it gives me following error.
Error using ==> times
Matrix dimensions must agree.
Error in ==> Untitled5 at 30
qpskModulated = ow.*quadPhaseOsc + ew.*inPhaseOsc;
Kindly help.
>> size(ow)
ans =
1 500
>> size(ew)
ans =
1 500
>> size(quadPhaseOsc)
ans =
1 1000
>> size(inPhaseOsc)
ans =
1 1000
>> a=[ 1 2 4 5];
>> b=[3 4 6];
>> a.*b;
??? Error using ==> times
Matrix dimensions must agree.
>> a=[ 1 2 4 5];
>> b=[3 4 5 6];
>> a.*b
ans =
3 8 20 30
i am separating odd bits and even bits from a binary sequence and then I am adding the respective bits to carrier oscillator. Could you plz correct my matlab code. It would be very helpful to me.
Thanx.
---------- Post added at 11:09 ---------- Previous post was at 10:32 ----------
Hello I made a change in my program.
Just have a look at it and tell me whether it is correct...
The program is as follows:
clc;
close all;
d = [0 1 1 1 0 1 0 0 1 0] % Data sequence
b = 2*d-1 % Convert unipolar to bipolar
Tb = 1 % Bit duration
fc = 3/Tb % Carrier frequency
Es = Tb/2 % This will result into unit amplitude waveforms
t = linspace(0, 10, 1000); % Discrete time samples between 0 and 10*Tb(1000 samples)
N = length(t) % Number of samples
Nsb = N/length(d) % Number of samples per bit
dd = repmat(d', 1, Nsb); % Replicate each bit Nsb times
bb = repmat(b', 1, Nsb);
dw = dd'; % Represent dw into a column vector(column by column)
dw = dw)'; % Represent dw into a row vector(row by row)
bw = bb'; % Represent bw into a column vector(column by column)
bw = bw)'; % Data sequence samples
o = b(1:2:end) %separating odd bits
e = b(2:2:end) %separating even bits
oo = repmat(o', 1, Nsb)
ee = repmat(e', 1, Nsb)
ow = oo'
ow = ow)'
ew = ee'
ew = ew)'
tc = linspace(0, 10, 500);
inPhaseOsc = 1/sqrt(2*Es/Tb)*cos(2*pi*fc*tc)
quadPhaseOsc = 1/sqrt(2*Es/Tb)*sin(2*pi*fc*tc)
qpskModulated = ow.*inPhaseOsc + ew.*quadPhaseOsc
% Plotting the waveforms
subplot(4,1,1);
plot(t,dw);axis([0 10 -1.5 1.5])
subplot(4,1,2);
plot(t,bw);axis([0 10 -1.5 1.5])
subplot(4,1,3);
plot(tc,qpskModulated);axis([0 10 -1.5 1.5])
Now I am getting plots..
How to generate delay in the following bit sequence using matlab.
My bit sequence is d= [1 0 1 1 0 1 0 1 1 0]
and my delay has to be d(n-1)...
What is the matlab code for generating delay d(n-1).
Thanx.
x=[ 1 2 3 4 5 6 7 8];%Sample Data
subplot(2,1,1)
stem(x)
grid on;
xlabel('n');
ylabel('X(n)');
Title('Sequence X(n)')
subplot(2,1,2)
stem([0,x(1:end-1)])%Delayed Data
grid on;
xlabel('n');
ylabel('X(n)');
title('Delayed Sequence X(n)');
I have to a generate a random binary sequence and then after generating the binary sequence I have to apply threshold of 0.5. Suppose for example - the random value generated is 0.112 ten since the value is greater than threshold then it will binary 1 and if the random values generated are less than 0.5 then it will binary 0.
I have written a matlab code for it as follows:
clc;
close all;
A = randn(1,1000) % Generate a random binary sequence
threshold = 0.5;
B = (A > threshold);
if any(B)
j = 1
else
j = 0
end
M not getting output.
Kindly help....
---------- Post added at 07:08 ---------- Previous post was at 06:51 ----------
I have modified my above matlab code as follows but still I am not getting the output.
clc;
close all;
A = randn(1,1000) % Generate a random binary sequence
threshold = 0.5;
for i=1:1000
if i>=threshold
A(i)=1;
else
A(i)=0;
end
end
clc;
close all;
A = randn(1,1000) ;% Generate a random binary sequence
threshold = 0.5;
for i=1:1000
if [B][COLOR="#0000FF"]A(i)>=threshold[/COLOR][/B]
A(i)=1;
else
A(i)=0;
end
end
>> A(1:20)
ans =
Columns 1 through 13
0 0 1 1 1 1 0 1 0 0 0 0 1
Columns 14 through 20
0 0 0 1 0 0 0
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?