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 ask modulation and demodulation in matlab

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,

I have written a matlab code for ask modulation and demodulation. I have taken 1 bit at a time, modulated tat bit, added noise to it and demodulated that bit to recover the original data bit. I need to modify this code for all the bits present in the data sequence.... I have to repeat the above steps for 10 bits... How to do tat.. kindly help... my code is as follows:

clc;
close all;
clear all;
no_of_bits=10;
no_of_samples=20;
threshold = 0.5;
snr=-3;
Tb = 1; % Bit duration
fc = 3/Tb; % Carrier frequency
t1=linspace(0, 1, no_of_samples);
t2=t1/fc;
w=cos(2*pi*fc*t2);
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
if (d(1)==1)
askmod=d(1).*w;
else
askmod=d(1);
end
a1=askmod % Modulated ask signal
% Noise addition
noise = (10^(-snr/20))*randn(1,no_of_samples);
received = a1 + noise;
% Multipying the received signal with carrier waveform
v = received.*w;
y=v;
z=trapz(y)
if z<0
z=0;
else
z=1;
end
bask=z
 

Hi,

I presume your considering 2 samples per bit,

firstly you want to ensure your 'd' variable corresponds to two samples per bit. i.e., you want to ensure d(2*i-1) and d(2*i) are the same for a two samples per bit scenario.

At the receiver similarly you will integrate over these two samples alone.

I suggest you also check your computation of noise, SNR is a power and divided by 10. Then the half power width is used to get N0/2.

Have fun
 

My ber values are 0.2509 for snr=3 and ber=0.2537 for snr=4... which are wrong values.. As snr increases, ber shld decrease.. Kindly help me in rectifying the problem in my code. I have taken no. of bits = 10^5 and no of samples per bit as 20... My matlab code is as follows:
clc;
close all;
clear all;
no_of_bits=10000;
no_of_samples=20;
threshold = 0.5;
snr=[-3:1:20];
A1=5; % Amplitude
Tb = 1; % Bit duration
fc = 3/Tb; % Carrier frequency
t1=linspace(0, 1, no_of_samples);
t2=t1/fc;
rand('state',123);
w=cos(2*pi*fc*t2);
for i=1:10;
ber(i)=0;
end
for k=1:length(snr)
sn(k)=snr(k)+6;
err(k)=0;
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
for j=1:length(d)
if (d(j)==1)
askmod=A1.*cos(2*pi*fc*t2);
else
askmod=0.*cos(2*pi*fc*t2);
end
askmod;
noise = (10^(-sn(k)/20))*randn(1,no_of_samples);
received = askmod + noise;
v=received.*cos(2*pi*fc*t2);
z=trapz(v);
baskout=[];
if (z<0)
baskout(j)=0;
else
baskout(j)=1;
end
baskout;
if (d(j)~=baskout(j))
err(k)=err(k)+1;
end
end
ber(k)=err(k)/(no_of_bits)
sn(k)
end
% plot
close all
figure
semilogy(sn,ber);
axis([3 26 10^-5 10^0]);
grid on;
xlabel('snr');
ylabel('Bit Error Rate');
title('Bit error probability curve for BASK modulation');
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top