send you my code:
close all
clear all
clc
%ASK..............
SNR=linspace(10,30,10);%dB
N=10^6;% number of bit
a1=3;a2=8; %amplitude for 0 bit & 1 bit.
A=[3 8];
f=3; % carrier frequency.
n=30;% number sample of bit.
bit_stream= round(rand(1,N));
fres=A(bit_stream+1);
bit_stream_sig= rectpulse(bit_stream,n);
t=linspace(0,1,30);carrier0=3*sin(2*pi*f*t);carrier1=a2*sin(2*pi*f*t);
% ask signal
for i=1:length(bit_stream)
if bit_stream(i)==0
ask_signal((i-1)*30+1:i*30)=carrier0;
else
ask_signal((i-1)*30+1:i*30)=carrier1;
end
end
plot(bit_stream_sig(1:8*30));hold on;plot(ask_signal(1:8*30),'r');
for ii=1:length(SNR)
ask_receive=awgn(ask_signal,SNR(ii),'measured');
%recover ask signal
ask_receive=ask_receive';
ask_receive = reshape(ask_receive,n,N);
[a b]= size(ask_receive);
for i=1:b
ask_receive
,i)=ask_receive
,i).*sin(2*pi*f*t)';
end;
ask_receive=round(mean(ask_receive,1)*2);
%bit error
N_err=biterr(ask_receive,fres);
BER(ii)=N_err/N;
end
figure(2)
semilogy(SNR,BER)
grid on
I would like this code can help you!have fun