ask without function

4
%%%%%%%%%%%%%%%%%%%%fsktest.m%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% clear; clc; close all; %+++++++++++++ASK MODULATION+++++++++++++++++++++++++++++++ Fs=input('Enter the sampling Freq (# of samples) \n '); N=input('Enter the length of Bit stream (Less than # of samples) \n '); Tr_Sig=[];%Modulated Signal M=2; k=log2(M); EbNo=5; %GENERATE MESSAGE SIGNAL Tb=1; m=rand(1,N); for i=1:N if m(i)>0.5 m(i)=1; else m(i)=0; end end for i=1:1:length(m) Msg_Sig(((i-1)*Fs)+1:i*Fs)=m(i);

Upload: annachithysalu

Post on 25-Sep-2015

212 views

Category:

Documents


0 download

DESCRIPTION

matlab code for ask without using function

TRANSCRIPT

%%%%%%%%%%%%%%%%%%%%fsktest.m%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clear;clc;close all;%+++++++++++++ASK MODULATION+++++++++++++++++++++++++++++++Fs=input('Enter the sampling Freq (# of samples) \n ');N=input('Enter the length of Bit stream (Less than # of samples) \n ');Tr_Sig=[];%Modulated SignalM=2; k=log2(M); EbNo=5;%GENERATE MESSAGE SIGNALTb=1;m=rand(1,N);for i=1:Nif m(i)>0.5m(i)=1;elsem(i)=0;endend

for i=1:1:length(m)Msg_Sig(((i-1)*Fs)+1:i*Fs)=m(i);endfor i=1:length(Msg_Sig) Msg_Sig1(i)=1-Msg_Sig(i);end%GENERATE CARRIER SIGNALfc1=10;fc2=20;t=0:(1/Fs):(length(m)-(1/Fs));% t=0:(Tb/Fs):Tb;c1=sqrt(2/Tb)*sin(2*pi*fc1*t);c2=0;Tr_Sig=c1.*Msg_Sig+c2.*Msg_Sig1;

subplot(3,1,1)plot(Msg_Sig)title('Message Signal');xlabel('t'),ylabel('amp');grid on ; axis([0 N*Fs -2 +2])subplot(3,1,2)plot(t,c1)title('Carrier Signal 1');xlabel('t'),ylabel('amp');grid on ; axis([0 1 -2 +2])

subplot(3,1,3)plot(Tr_Sig)title('Transmitted Signal');xlabel('t'),ylabel('amp');grid on ; axis([0 N*Fs -2 +2])% %+++++++++++++FSK MODULATION+++++++++++++++++++++++++++++++for i=1:10 msg_rx = awgn(Tr_Sig,EbNo+10*log10(k)-10*log10(Fs),... 'measured',[],'dB'); % AWGN channel % msg_rx=Tr_Sig;

% Msg_Demod = fskdemod(msg_rx,M,100,Fs,100); % Demodulatet1=0:Tb/Fs:Tb-(Tb/Fs);c11=sqrt(2/Tb)*sin(2*pi*fc1*t1);c22=0; fft_length=length(Tr_Sig)+length(c11)-1; FFT_TrSig=fft(msg_rx ,fft_length); FFT_c11=fft(fliplr(c11),fft_length); FFT_c22=fft(fliplr(c22),fft_length); co1=FFT_TrSig.*FFT_c11; cor1=ifft(co1,fft_length); co2=FFT_TrSig.*FFT_c22; cor2=ifft(co2,fft_length); X=cor1-cor2; for z=1:length(m) t(z)=X(z*Fs); if t(z)>0 Msg_Demod(z)=1;elseMsg_Demod(z)=0; end end for j=1:1:length(m)Msg_Demod1(((j-1)*Fs)+1:j*Fs)=Msg_Demod(j);end [num,BER] = biterr(Msg_Sig,Msg_Demod1); end%l=length(a);

%figure,berfit(EbNo,a);figuresubplot(2,1,1)plot(msg_rx)title('Received Signal');xlabel('t'),ylabel('amp');grid on ; axis([0 N*Fs -2 +2])subplot(2,1,2)plot(Msg_Demod1)title('Demodulated Signal');xlabel('t'),ylabel('amp');grid on ; axis([0 N*Fs -2 +2])