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.

Help in error in matlab code

Status
Not open for further replies.

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 everyone,

I have written a matlab code for BPSK modulation. Here in the program, I have first generated random binary bits. Modulated the bits with BPSK modulation. Added noise to the bpsk modulated signal. My matlab code is as follows:

clc;
close all;
clear all;
no_of_bits=10;
no_of_samples=10;
threshold = 0.5;
A = rand(1,no_of_bits); % Generate a random sequence
for i=1:no_of_bits
if (A(i)>=threshold)
A(i)=1;
else
A(i)=0;
end
end
d = A(1:no_of_bits) % Binary sequence
% BPSK modulation
Tb = 1; % Bit duration
fc = 3/Tb; % Carrier frequency
t1=linspace(0, 1, no_of_samples);
t2=t1/fc;
M=2; % Number of symbols
theta=([0:M-1]*2*pi)/M; % Reference phase values
PhaseOsc1=cos(2*pi*fc*t2)
PhaseOsc2=cos(theta) % Carrier waveform
b = 2*d-1 % Bipolar sequence
for i=1:no_of_bits
for j=1:no_of_samples
b1(j)=b(i)
end
bpskmod=b1.*PhaseOsc1.*PhaseOsc2; % Modulated bpsk waveform
end
noise = randn(1,no_of_samples); % Noise addition
recbpsk = bpskmod + noise;

After running the above program, it gives me following error:
Error in ==> abc1 at 30
bpskmod=b1.*PhaseOsc1.*PhaseOsc2; % Modulated bpsk waveform

Kindly help me in correcting the above error.
 

Hi.. I have the code, which works for me.. you can try this.

d=[1 0 1 0 1 ]; % Data sequence
b=2*d-1; % Convert unipolar to bipolar
T=1; % Bit duration
Eb=T/2; % This will result in unit amplitude waveforms
fc=1; % Carrier frequency
t=linspace(0,5,10000); % discrete time sequence between 0 and 5*T (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'; % Transpose the rows and columns
dw=dw:))'; % Convert dw to a column vector (colum by column) and convert to a row vector
bw=bb';
bw=bw:))'; % Data sequence samples
w=sqrt(2*Eb/T)*cos(2*pi*fc*t); % carrier waveform
bpsk_w=bw.*w; % modulated waveform

% plotting commands follow

subplot(4,1,1);
plot(t,dw); axis([0 5 -1.5 1.5])

subplot(4,1,2);
plot(t,bw); axis([0 5 -1.5 1.5])

subplot(4,1,3);
plot(t,w); axis([0 5 -1.5 1.5])

subplot(4,1,4);
plot(t,bpsk_w,'.'); axis([0 5 -1.5 1.5])
xlabel('time')


If you find any query in this.. tell me.

- - - Updated - - -

Hi.. I have the code, which works for me.. you can try this.

d=[1 0 1 0 1 ]; % Data sequence
b=2*d-1; % Convert unipolar to bipolar
T=1; % Bit duration
Eb=T/2; % This will result in unit amplitude waveforms
fc=1; % Carrier frequency
t=linspace(0,5,10000); % discrete time sequence between 0 and 5*T (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'; % Transpose the rows and columns
dw=dw:))'; % Convert dw to a column vector (colum by column) and convert to a row vector
bw=bb';
bw=bw:))'; % Data sequence samples
w=sqrt(2*Eb/T)*cos(2*pi*fc*t); % carrier waveform
bpsk_w=bw.*w; % modulated waveform

% plotting commands follow

subplot(4,1,1);
plot(t,dw); axis([0 5 -1.5 1.5])

subplot(4,1,2);
plot(t,bw); axis([0 5 -1.5 1.5])

subplot(4,1,3);
plot(t,w); axis([0 5 -1.5 1.5])

subplot(4,1,4);
plot(t,bpsk_w,'.'); axis([0 5 -1.5 1.5])
xlabel('time')


If you find any query in this.. tell me.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top