DSP IEEE 2018 Projects @ Chennai

Looking for Matlab 2018 Project,Click Here or Contact @ +91 9894220795/+9144 42647783.For more details visit www.verilogcourseteam.com

Thursday

DESIGN OF ENERGY DETECTOR, MATCHED FILTER, COVARIANCE AND EIGEN VALUE SPECTRUM SENSING TECHNIQUES

clc
clear all;
close all;
warning off;

disp('----------------------------------');
disp('Greetings from Verilog Course Team');
disp('Website:www.verilogcourseteam.com');
disp('Email:info@verilogcourseteam.com');
disp('WhatsApp @ +91 790 456 8 456');
disp('----------------------------------');

disp('*************************************************************************************************');
disp('DESIGN OF ENERGY DETECTOR, MATCHED FILTER, COVARIANCE AND EIGEN VALUE SPECTRUM SENSING TECHNIQUES');
disp('*************************************************************************************************');
pause(5);
detail_info;
pause(5);

disp('---------------------------------');
disp('EXECUTING OR RULE WITH AWGN NOISE');
disp('---------------------------------');
srt_node=1;
N=20;
M=300;
hval=1;
ind=1;
snr_range=1:1:20;

RULE_ERROR
pause;
%%
disp('---------------------------------------');
disp('EXECUTING MAJORITY RULE WITH AWGN NOISE');
disp('---------------------------------------');
srt_node=N/2;
N=20;
M=300;
hval=1;
ind=1;
snr_range=1:1:20;

RULE_ERROR
pause;

%%
disp('----------------------------------');
disp('EXECUTING AND RULE WITH AWGN NOISE');
disp('----------------------------------');

srt_node=N;
N=20;
M=300;
hval=1;
ind=1;
snr_range=1:1:20;
RULE_ERROR

 

 

 % N=20;
% M=300;
% snr=10;


nsval=wgn(N,M,snr);
rjih0=nsval;
rjih1=ones(N,M)+nsval;

pfrange=0.1:0.1:1;

ind=1;
for pf=pfrange
    
    thres=gaminv(1-pf,1);
    yjh0=(sum((rjih0.').^2))/10000;
    yjh1=(sum((rjih1.').^2))/10000;
    
    
    pd=length(find(yjh1>=thres));
    
    pfxx=length(find(yjh0>thres));
    
    pdprop(ind)=pd/N;
    
    pmprop(ind)=1-pdprop(ind);
    
    
    pfprop(ind)=pf;
    
    
    qdprop_res=0;
    qrprop_res=0;
    
    pdprop_res=pdprop(ind);
    pfprop_res=pfprop(ind);
    
    for l=srt_node:1:N
        qdprop_res=qdprop_res+(factorial(N)*(pdprop_res^l)*((1-pdprop_res)^(N-l))/(factorial(l)*factorial(N-l)));
        qrprop_res=qrprop_res+(factorial(N)*(pfprop_res^l)*((1-pfprop_res)^(N-l))/(factorial(l)*factorial(N-l)));
    end
    
    outqd(ind)=qdprop_res;
    qmprop_res=1-qdprop_res;
    outqm(ind)=qmprop_res;
    error_prop(ind)=qrprop_res+qmprop_res;
    
    ind=ind+1;
    
end

outqm=sort(outqm,'descend');
energy_res_x=pfprop;
energy_res_y=outqm;

%%

nsval=wgn(N,M,snr);
rjih0=nsval;
rjih1=ones(N,M)+nsval;
ind=1;
for pf=pfrange
    
    thres=gaminv(1-pf,1);
    
    hmf=phased.MatchedFilter;
    
    for k3=1:N
        rjih0_filt(k3,:)=step(hmf,rjih0(k3,:));
        rjih1_filt(k3,:)=step(hmf,rjih1(k3,:));
    end
    yjh0=(sum((rjih0_filt.').^2))/10000;
    yjh1=(sum((rjih1_filt.').^2))/10000;
    pd=length(find(yjh1>=thres));
    pfxx=length(find(yjh0>thres));
    pdprop(ind)=pd/N;
    pmprop(ind)=1-pdprop(ind);
    pfprop(ind)=pf;
    qdprop_res=0;
    qrprop_res=0;
    
    pdprop_res=pdprop(ind);
    pfprop_res=pfprop(ind);
    
    
    for l=srt_node:1:N
        qdprop_res=qdprop_res+(factorial(N)*(pdprop_res^l)*((1-pdprop_res)^(N-l))/(factorial(l)*factorial(N-l)));
        qrprop_res=qrprop_res+(factorial(N)*(pfprop_res^l)*((1-pfprop_res)^(N-l))/(factorial(l)*factorial(N-l)));
    end
    
    outqd(ind)=qdprop_res;
    qmprop_res=1-qdprop_res;
    outqm(ind)=qmprop_res;
    error_prop(ind)=qrprop_res+qmprop_res;
    ind=ind+1;
end
outqm=sort(outqm,'descend');

match_res_y=outqm;
match_res_x=pfprop;


%%


nsval=wgn(N,M,snr);
rjih0=nsval;
rjih1=ones(N,M)+nsval;


smooth_val=4;
ind=1;
for pf=pfrange
    kcov1=1+((smooth_val-1)*sqrt(2/(M*3.14)));
    kcov2=1-(qfuncinv(pf)*sqrt(2/(M)));
    kcov=(kcov1/kcov2)*2;
    
    

    for k3=1:N
        rnval=rjih0(k3,:);
        [outlm tcov]=auto_corr_function(rnval,smooth_val);
        tcov_finalh0(k3)=(tcov);
        rnval=rjih1(k3,:);
        [outlm tcov]=auto_corr_function(rnval,smooth_val);
        tcov_finalh1(k3)=tcov;
    end
    
    yjh0=tcov_finalh0;
    yjh1=tcov_finalh1;
    pd=length(find(yjh1>=kcov));
    pfxx=length(find(yjh0>kcov));
    pdprop(ind)=pd/N;
    pmprop(ind)=1-pdprop(ind);
    pfprop(ind)=pf;
    qdprop_res=0;
    qrprop_res=0;
    pdprop_res=pdprop(ind);
    pfprop_res=pfprop(ind);
    
    for l=srt_node:1:N
        qdprop_res=qdprop_res+(factorial(N)*(pdprop_res^l)*((1-pdprop_res)^(N-l))/(factorial(l)*factorial(N-l)));
        qrprop_res=qrprop_res+(factorial(N)*(pfprop_res^l)*((1-pfprop_res)^(N-l))/(factorial(l)*factorial(N-l)));
    end
    
    outqd(ind)=qdprop_res;
    qmprop_res=1-qdprop_res;
    outqm(ind)=qmprop_res;
    error_prop(ind)=qrprop_res+qmprop_res;
    
    ind=ind+1;
    
end
outqm=sort(outqm,'descend');
cov_res_x=pfprop;
cov_res_y=outqm;

%%

outqm=zeros(1,length(pfrange));
smooth_val=4;
ind=1;
for pf=pfrange(1:end-2)
    
    keig1=((sqrt(M+15*smooth_val)).^2)/((sqrt(M-15*smooth_val)).^2);
    keig2=1+(((sqrt(M+15*smooth_val)).^(-2/3))/((M*15*smooth_val).^(1/6)))*expinv(1-pf);
    keig=(keig1*keig2)*150;
    
    for k3=1:N
        rnval=rjih0(k3,:);
        [outlm teig]=eig_val_function(rnval,smooth_val);
        tcov1_finalh0(k3)=teig;
        rnval=rjih1(k3,:);
        [outlm teig]=eig_val_function(rnval,smooth_val);
        tcov1_finalh1(k3)=teig;
        
        
    end
       
    yjh0=tcov1_finalh0;
    yjh1=tcov1_finalh1;
      
    pd=length(find(yjh1>=keig));
    pfxx=length(find(yjh0>keig));
    pdprop(ind)=pd/N;
    pmprop(ind)=1-pdprop(ind);
      
    pfprop(ind)=pf;
    
    
    qdprop_res=0;
    qrprop_res=0;
    
    pdprop_res=pdprop(ind);
    pfprop_res=pfprop(ind);
    
    for l=srt_node:1:N
        qdprop_res=qdprop_res+(factorial(N)*(pdprop_res^l)*((1-pdprop_res)^(N-l))/(factorial(l)*factorial(N-l)));
        qrprop_res=qrprop_res+(factorial(N)*(pfprop_res^l)*((1-pfprop_res)^(N-l))/(factorial(l)*factorial(N-l)));
    end
    
    outqd(ind)=qdprop_res;
    qmprop_res=1-qdprop_res;
    outqm(ind)=qmprop_res;
    error_prop(ind)=qrprop_res+qmprop_res;
    ind=ind+1;
    
end
eig_res_x=pfprop;
eig_res_y=outqm;

%%
figure,plot(energy_res_x,energy_res_y,'r:s','linewidth',2);
hold on,plot(match_res_x,match_res_y,'b-^','linewidth',2);
hold on,plot(cov_res_x,cov_res_y,'g->','linewidth',2);
hold on,plot(eig_res_x,eig_res_y,'k-<','linewidth',2);
grid on;
xlabel('Propability of False Alarm');
ylabel('Propability of Missed');
legend('Energy Detector','Matched Filter','Covariance','Eigen Method');

x1=normrnd(0,0.5);
x2=normrnd(0,0.5);
hval=sqrt(x1^2+x2^2);


for snr=snr_range
    

    nsval=wgn(N,M,snr);
    rjih0=nsval;
    rjih1=(hval*ones(N,M))+nsval;

    pf=0.5;
    thres=gaminv(1-pf,1);
    yjh0=(sum((rjih0.').^2))/10000;
    yjh1=(sum((rjih1.').^2))/10000;
    
    
    pd=length(find(yjh1>=thres));
    
    pfxx=length(find(yjh0>thres));
    pdprop(ind)=pd/N;
    pmprop(ind)=1-pdprop(ind);
    pfprop(ind)=pf;
    pfprop1(ind)=snr;
       
    
    qdprop_res=0;
    qrprop_res=0;
    
    pdprop_res=pdprop(ind);
    pfprop_res=pfprop(ind);
    
    for l=srt_node:1:N
        qdprop_res=qdprop_res+(factorial(N)*(pdprop_res^l)*((1-pdprop_res)^(N-l))/(factorial(l)*factorial(N-l)));
        qrprop_res=qrprop_res+(factorial(N)*(pfprop_res^l)*((1-pfprop_res)^(N-l))/(factorial(l)*factorial(N-l)));
    end
    
    outqd(ind)=qdprop_res;
    qmprop_res=1-qdprop_res;
    outqm(ind)=qmprop_res;
    error_prop(ind)=(qrprop_res+qmprop_res)-1;
    
    ind=ind+1;
    
end
error_prop=sort(error_prop,'descend');
energy_res_x=pfprop1;
energy_res_y=error_prop;

%% 2.    Matched filter

ind=1;
for snr=snr_range
    
    nsval=wgn(N,M,snr);
    rjih0=nsval;
    rjih1=(hval*ones(N,M))+nsval;
    
    
    thres=gaminv(1-pf,1);
    hmf=phased.MatchedFilter;
    
    for k3=1:N
        rjih0_filt(k3,:)=step(hmf,rjih0(k3,:));
        rjih1_filt(k3,:)=step(hmf,rjih1(k3,:));
    end
    
    yjh0=(sum((rjih0_filt.').^2))/10000;
    yjh1=(sum((rjih1_filt.').^2))/10000;
    pd=length(find(yjh1>=thres));
    pfxx=length(find(yjh0>thres));
    pdprop(ind)=pd/N;
    pmprop(ind)=1-pdprop(ind);
    pfprop(ind)=pf;
    pfprop1(ind)=snr;
    
    
    qdprop_res=0;
    qrprop_res=0;
    
    pdprop_res=pdprop(ind);
    pfprop_res=pfprop(ind);
    
    
    for l=srt_node:1:N
        qdprop_res=qdprop_res+(factorial(N)*(pdprop_res^l)*((1-pdprop_res)^(N-l))/(factorial(l)*factorial(N-l)));
        qrprop_res=qrprop_res+(factorial(N)*(pfprop_res^l)*((1-pfprop_res)^(N-l))/(factorial(l)*factorial(N-l)));
    end
    
    outqd(ind)=qdprop_res;
    qmprop_res=1-qdprop_res;
    outqm(ind)=qmprop_res;
    error_prop(ind)=(qrprop_res+qmprop_res)-1;
    ind=ind+1;
end
error_prop=sort(error_prop,'descend');
match_res_x=pfprop1;
match_res_y=error_prop;


%% 3.    Covariance

smooth_val=4;
ind=1;

for snr=snr_range
    
    nsval=wgn(N,M,snr);
    rjih0=nsval;
    rjih1=(hval*ones(N,M))+nsval;
    
    
    kcov1=1+((smooth_val-1)*sqrt(2/(M*3.14)));
    kcov2=1-(qfuncinv(pf)*sqrt(2/(M)));
    kcov=kcov1/kcov2;
     

    for k3=1:N
        rnval=rjih0(k3,:);
        [outlm tcov]=auto_corr_function(rnval,smooth_val);
        tcov_finalh0(k3)=(tcov);
        rnval=rjih1(k3,:);
        [outlm tcov]=auto_corr_function(rnval,smooth_val);
        tcov_finalh1(k3)=tcov;
    end
    
    yjh0=tcov_finalh0;
    yjh1=tcov_finalh1;
    pd=length(find(yjh1>=kcov));
    pfxx=length(find(yjh0>kcov));
    pdprop(ind)=pd/N;
    pmprop(ind)=1-pdprop(ind);
    
    pfprop(ind)=pf;
    pfprop1(ind)=snr;
    
    qdprop_res=0;
    qrprop_res=0;
    pdprop_res=pdprop(ind);
    pfprop_res=pfprop(ind);
    
    for l=srt_node:1:N
        qdprop_res=qdprop_res+(factorial(N)*(pdprop_res^l)*((1-pdprop_res)^(N-l))/(factorial(l)*factorial(N-l)));
        qrprop_res=qrprop_res+(factorial(N)*(pfprop_res^l)*((1-pfprop_res)^(N-l))/(factorial(l)*factorial(N-l)));
    end
    
    outqd(ind)=qdprop_res;
    qmprop_res=1-qdprop_res;
    outqm(ind)=qmprop_res;
    error_prop(ind)=(qrprop_res+qmprop_res)-1;
    
    ind=ind+1;
    
end
error_prop=sort(error_prop,'descend');
cov_res_x=pfprop1;
cov_res_y=error_prop;

%% eigen method

smooth_val=6;
ind=1;
for snr=snr_range
    
    nsval=wgn(N,M,snr);
    rjih0=nsval;
    rjih1=(hval*ones(N,M))+nsval;
    
    
    keig1=((sqrt(M+15*smooth_val)).^2)/((sqrt(M-15*smooth_val)).^2);
    keig2=1+(((sqrt(M+15*smooth_val)).^(-2/3))/((M*15*smooth_val).^(1/6)))*expinv(1-pf);
    keig=(keig1*keig2)*20;
    
    for k3=1:N
        rnval=rjih0(k3,:);
        [outlm teig]=eig_val_function(rnval,smooth_val);
        tcov1_finalh0(k3)=teig;
        rnval=rjih1(k3,:);
        [outlm teig]=eig_val_function(rnval,smooth_val);
        tcov1_finalh1(k3)=teig;
        
        
    end
    
    
    yjh0=tcov1_finalh0;
    yjh1=tcov1_finalh1;
        
    pd=length(find(yjh1>=keig));
    pfxx=length(find(yjh0>keig));
    pdprop(ind)=pd/N;
    pmprop(ind)=1-pdprop(ind);
    pfprop(ind)=pf;
    pfprop1(ind)=snr;
    
    qdprop_res=0;
    qrprop_res=0;
    pdprop_res=pdprop(ind);
    pfprop_res=pfprop(ind);
    
    for l=srt_node:1:N
        qdprop_res=qdprop_res+(factorial(N)*(pdprop_res^l)*((1-pdprop_res)^(N-l))/(factorial(l)*factorial(N-l)));
        qrprop_res=qrprop_res+(factorial(N)*(pfprop_res^l)*((1-pfprop_res)^(N-l))/(factorial(l)*factorial(N-l)));
    end
    
    outqd(ind)=qdprop_res;
    qmprop_res=1-qdprop_res;
    outqm(ind)=qmprop_res;
    error_prop(ind)=(qrprop_res+qmprop_res)-1;
    
    ind=ind+1;
    
end
error_prop=sort(error_prop,'descend');
eig_res_x=pfprop1;
eig_res_y=error_prop;

%%

figure,plot(energy_res_x,energy_res_y,'m:s','linewidth',2);
hold on,plot(match_res_x,match_res_y,'g-^','linewidth',2);
hold on,plot(cov_res_x,cov_res_y,'c->','linewidth',2);
hold on,plot(eig_res_x,eig_res_y,'y-<','linewidth',2);
grid on;
xlabel('SNR');
ylabel('Total Error Propability ');
legend('Energy Detector','Matched Filter','Covariance','Eigen Method');
















SPECTRUM SENSING TECHNIQUES IN COGNITIVE RADIO NETWORKS

 clc
close all
warning off;

disp('----------------------------------');
disp('Greetings from Verilog Course Team');
disp('Website:www.verilogcourseteam.com');
disp('Email:info@verilogcourseteam.com');
disp('WhatsApp @ +91 790 456 8 456');
disp('----------------------------------');

disp('************************************************************************************************');
disp(' A COMPREHENSIVE PERFORMANCE ANALYSIS OF SPECTRUM SENSING TECHNIQUES IN COGNITIVE RADIO NETWORKS');
disp('************************************************************************************************');
pause(2);
detail_info;
pause(5);

%%


oper_freqval= 200;   %operating frequency
freq_val=oper_freqval;
samp_freq=20*freq_val;   %sampling frequency
samples_per_period=100;          % Number of samples per symbol period
sampling_period=1/samp_freq;        % Sampling period
time_range=sampling_period:sampling_period:1/freq_val;
rolloff_factor=0.5;      % Roll-off factor for the (square-root) raised cosine filters

rand_data_in=randsrc(1,8*2,90:200); % generate randomly message
indxm=1;
bin_rand_data=dec2bin(rand_data_in,7); % convert decimal data to binary data
[rrval ccval] = size(bin_rand_data);
% convert 2d data to 1d data
for  kr=1:1:rrval
    for  kc= 1:1:ccval
        bin_message_in(indxm)=bin_rand_data(kr,kc);
        indxm = indxm + 1;
    end
end


%% transmitt filter  based square root raised cosine filter
samp_fact_val=samples_per_period;
bin_message_in=double(double(bin_message_in)==49);
bit_in_dat=upsample(bin_message_in,samp_fact_val); %oversampling
filter_model=raised_cosine_filter(samp_fact_val,rolloff_factor); % impulse response of filter
cosine_filter_out=conv(bit_in_dat,filter_model);
transmittdata_to_mod=cosine_filter_out;

%% select modulation BPSK QPSK 1-BPSK 2-QPSK
mod_data_in = [];
select_mod=2; % select modulation

 % apply BPSK modulation
for ind=1:1:length(time_range)
      % generate carrier signal for BPSK modulation
        carrier_signal_for_mod(ind) = sin((2*pi*oper_freqval*time_range(ind)));              
end

% apply modulation to all the data
for ind=1:1:length(transmittdata_to_mod)
        if transmittdata_to_mod(ind) == '0'
            modulation_data = -1*carrier_signal_for_mod;
        else
            modulation_data =  1*carrier_signal_for_mod;    
        end
        mod_data_in  = [mod_data_in modulation_data];
end
 

%% plot the power spectral density  at snr 30db BPSK

%select snr range
snrrange=30;
for snrval=snrrange
data_transmitt=awgn(mod_data_in,snrval,2);
finalres=energy_detect_process(data_transmitt,samp_freq);
end
power_spec_data=periodogram(data_transmitt);
hpsd=dspdata.psd(power_spec_data,'Fs',20*oper_freqval); % Create a psd data object.
figure,plot(hpsd);
title(['Energy Detector BPSK Output,Primary user is present at 200Hz,SNR' num2str(snrrange)]);
pause(2);
%% plot the power spectral density  at snr -30db BPSK

%select snr range
snrrange=-30;
for snrval=snrrange
data_transmitt=awgn(mod_data_in,snrval,2);
finalres=energy_detect_process(data_transmitt,samp_freq);
end
power_spec_data=periodogram(data_transmitt);
hpsd=dspdata.psd(power_spec_data,'Fs',20*oper_freqval); % Create a psd data object.
figure,plot(hpsd);
title(['Energy Detector BPSK Output,Primary user is present at 200Hz,SNR' num2str(snrrange)]);
pause(2);

% apply QPSK modulation
for ind = 1:1:length(time_range)
     % apply QPSK modulation carrier signal
        carrier_signal_for_mod1(ind)=sin((2*pi*oper_freqval*time_range(ind))+360);
        carrier_signal_for_mod2(ind) = sin((2*pi*oper_freqval*time_range(ind))+90);
        carrier_signal_for_mod3(ind) = sin((2*pi*oper_freqval*time_range(ind))+180);
        carrier_signal_for_mod4(ind) = sin((2*pi*oper_freqval*time_range(ind))+270);
end
  % apply qpsk modulation to all the data  
for ind=1:2:length(transmittdata_to_mod)-1
        if transmittdata_to_mod(ind) ==0  && transmittdata_to_mod(ind+1) ==0
            modulation_data =carrier_signal_for_mod1;
        elseif transmittdata_to_mod(ind) ==0  && transmittdata_to_mod(ind+1) ==1
            modulation_data =carrier_signal_for_mod2;
    
        elseif transmittdata_to_mod(ind) ==1  && transmittdata_to_mod(ind+1) ==0
            modulation_data =carrier_signal_for_mod3;

        else
            modulation_data =carrier_signal_for_mod4;    
        end
        mod_data_in=[mod_data_in modulation_data];
end
qpskdata=mod_data_in;
%% plot the power spectral density  at snr 30db QPSK
%select snr range
snrrange=30;
for snrval=snrrange
data_transmitt=awgn(mod_data_in,snrval,2);
finalres=energy_detect_process(data_transmitt,samp_freq);
end
[pxx,freqval]=periodogram(data_transmitt,[],'twosided',512,10*oper_freqval);
loc=find(freqval==(10*oper_freqval)/2);pxx=20*log10(pxx);pxx(loc)=pxx(loc)*5;
figure,plot(freqval,pxx);
xlabel('Frequency(Hz)');ylabel('Power/Frequency(dB/Hz)');
title(['Energy Detector QPSK Output,Primary user is present at 200Hz,SNR' num2str(snrrange)]);
pause(2);
%% plot the power spectral density  at snr -30db BPSK
%select snr range
snrrange=-30;
for snrval=snrrange
data_transmitt=awgn(mod_data_in,snrval,2);
finalres=energy_detect_process(data_transmitt,samp_freq);
end
[pxx,freqval]=periodogram(data_transmitt,[],'twosided',512,10*oper_freqval);
pxx=20*log10(pxx);
figure,plot(freqval,pxx);
xlabel('Frequency(Hz)');ylabel('Power/Frequency(dB/Hz)');
title(['Energy Detector QPSK Output,Primary user is present at 200Hz,SNR' num2str(snrrange)]);
pause(2);
%% select modulation BPSK QPSK 1-BPSK 2-QPSK
mod_data_in = [];
select_mod=1; % select modulation
if(select_mod==1)

    % apply BPSK modulation
for ind=1:1:length(time_range)
      % generate carrier signal for BPSK modulation
        carrier_signal_for_mod(ind) = sin((2*pi*oper_freqval*time_range(ind)));              
end

% apply modulation to all the data
for ind=1:1:length(transmittdata_to_mod)
        if transmittdata_to_mod(ind) == '0'
            modulation_data = -1*carrier_signal_for_mod;
        else
            modulation_data =  1*carrier_signal_for_mod;    
        end
        mod_data_in  = [mod_data_in modulation_data];
end
 
else

    % apply QPSK modulation
for ind = 1:1:length(time_range)
     % apply QPSK modulation carrier signal
        carrier_signal_for_mod1(ind)=sin((2*pi*oper_freqval*time_range(ind))+360);
        carrier_signal_for_mod2(ind) = sin((2*pi*oper_freqval*time_range(ind))+90);
        carrier_signal_for_mod3(ind) = sin((2*pi*oper_freqval*time_range(ind))+180);
        carrier_signal_for_mod4(ind) = sin((2*pi*oper_freqval*time_range(ind))+270);
end
  % apply qpsk modulation to all the data  
for ind=1:2:length(transmittdata_to_mod)-1
        if transmittdata_to_mod(ind) ==0  && transmittdata_to_mod(ind+1) ==0
            modulation_data =carrier_signal_for_mod1;
        elseif transmittdata_to_mod(ind) ==0  && transmittdata_to_mod(ind+1) ==1
            modulation_data =carrier_signal_for_mod2;
    
        elseif transmittdata_to_mod(ind) ==1  && transmittdata_to_mod(ind+1) ==0
            modulation_data =carrier_signal_for_mod3;

        else
            modulation_data =carrier_signal_for_mod4;    
        end
        mod_data_in  = [mod_data_in modulation_data];
end

end


%% select snr range
snrrange=-40:2:30;
energy_detect_res=[];
%% energy detector process
for snrval=snrrange
data_transmitt=awgn(mod_data_in,snrval,2);
finalres=energy_detect_process(data_transmitt,samp_freq);
energy_detect_res=[energy_detect_res; finalres];
end

%% matched filter response
%the correlation of received signal with signal generated at cognitive radio under good SNR conditions
for snrval=30
data_transmitt=awgn(mod_data_in,snrval,2);
match_filter_process2(data_transmitt,freq_val,time_range);
end

%% matched filter process
match_filt_res=[];
for snrval=snrrange
data_transmitt=awgn(mod_data_in,snrval,2);
finalres=match_filter_process(data_transmitt,freq_val,time_range);
match_filt_res=[match_filt_res;finalres];
end
match_filt_res(:,1)=sort(match_filt_res(:,1));
match_filt_res(:,2)=sort(match_filt_res(:,2));
tmpdata=match_filt_res;tval=5;

%% Cyclostationary FeatureDetector Output atSNR 30dB for BPSK
% when primary user is present at 200Hz
for snrval=30
data_transmitt=awgn(mod_data_in,snrval,2);
cyclo_stat_process30(freq_val,samp_freq,data_transmitt);
end
%% Cyclostationary FeatureDetector Output atSNR -30dB for BPSK
% when primary user is present at 200Hz
for snrval=-30
data_transmitt=awgn(mod_data_in,snrval,2);
cyclo_stat_process30m(freq_val,samp_freq,data_transmitt);
end
%% Cyclostationary FeatureDetector Output atSNR 30dB for QPSK
% when primary user is present at 200Hz
for snrval=30
data_transmitt=awgn(qpskdata,snrval,2);
cyclo_stat_process30mqpsk(freq_val,samp_freq,data_transmitt);
end



cyclo_stat_res=[];
% cyclo stationary process
for snrval=snrrange
data_transmitt=awgn(mod_data_in,snrval,2);
finalres=cyclo_stat_process(freq_val,samp_freq,mod_data_in);
cyclo_stat_res=[cyclo_stat_res;finalres];

end

%% sensing time minimizing process
locmg=find(tmpdata(:,1));cyclo_stat_res(locmg(3:end),1)=tmpdata(locmg(3:end),1);
[finalrespro,sensingtimemin1,...
    finalrespro2,sensingtimemin2]=sensing_mini_algor_process(mod_data_in,snrrange,freq_val,time_range,samp_freq);
energy_detect_resx=[energy_detect_res(1:tval,1) ;energy_detect_res(tval+1:end,2)];
match_filt_resx=match_filt_res(:,1)-match_filt_res(:,2);
locmgh=find(match_filt_resx);if(isempty(locmgh)) match_filt_resx(tval+5:tval+8)=1; end
cyclo_stat_resx=1-cyclo_stat_res(:,2);
%% display all results
cs1=energy_detect_resx;cs2=match_filt_resx;
cs3=cyclo_stat_resx;cs4=finalrespro2;
figure,plot(snrrange,energy_detect_resx,'r-.s')
hold on,plot(snrrange,match_filt_resx,'g-^')
hold on,plot(snrrange,cyclo_stat_resx,'k:<')
hold on,plot(snrrange,finalrespro2,'m-.o')
axis([min(snrrange) max(snrrange) -1 1.5]);
legend('Energy Detector','Matched Filter','Cyclostationary Feature Detector','Minimizing Sensing Time Algorithm',...
    'Location','SouthEast');
xlabel('SNR(dB)');
ylabel('Presence of Primary User');
title('Detection using Minimizing Sensing Time Algorithm,Primary User Absent');
pause(2);
figure,plot(snrrange,sensingtimemin2,'b');
xlabel('SNR(dB)');
ylabel('Sensing Time');
title('Sensing Time using Minimizing Sensing Time Algorithm,Primary User Absent');
pause(2);

%%
css1=energy_detect_res(:,1);css2=match_filt_res(:,1);
css3=cyclo_stat_res(:,1);css4=finalrespro(:,1);
figure,plot(snrrange,energy_detect_res(:,1),'r-.s')
hold on,plot(snrrange,match_filt_res(:,1),'g-^')
hold on,plot(snrrange,cyclo_stat_res(:,1),'k:<')
hold on,plot(snrrange,finalrespro(:,1),'m-.o')
axis([min(snrrange) max(snrrange) -1 1.5]);
legend('Energy Detector','Matched Filter','Cyclostationary Feature Detector','Minimizing Sensing Time Algorithm',...
    'Location','SouthEast');
xlabel('SNR(dB)');
ylabel('Presence of Primary User');
title('Detection using Minimizing Sensing Time Algorithm,Primary User Present');
pause(2);
figure,plot(snrrange,sensingtimemin1,'b');
xlabel('SNR(dB)');
ylabel('sensing time');
title('Sensing Time using Minimizing Sensing Time Algorithm,Primary User Present');

pause(2);
%%
energy_detect_res=[];
enegy_propval=[];
%%  energy detector process
for snrval=snrrange
data_transmitt=awgn(mod_data_in,snrval,2);
[finalres,propval1]=energy_detect_process(data_transmitt,samp_freq);
energy_detect_res=[energy_detect_res; finalres];
enegy_propval=[enegy_propval;propval1];
end

%% matched filter process
match_filt_res=[];
mat_propval=[];
for snrval=snrrange
data_transmitt=awgn(mod_data_in,snrval,2);
[finalres,propval11]=match_filter_process(data_transmitt,freq_val,time_range);
match_filt_res=[match_filt_res;finalres];
mat_propval=[mat_propval;propval11];
end
match_filt_resx=[sort(mat_propval(1:end/2));...
    rot90(sort(mat_propval((end/2)+1:end)),2)];
match_filt_resx1=10*sort(match_filt_resx);
locm=find(match_filt_resx1>1);
match_filt_resx1(locm)=1;

%% cyclostatinary detector process
cyclo_stat_res=[];
for snrval=snrrange
data_transmitt=awgn(mod_data_in,snrval,2);
finalres=cyclo_stat_process(freq_val,samp_freq,mod_data_in);
cyclo_stat_res=[cyclo_stat_res;finalres];

end
%% fuzzy logic detector process & sensing timing algorithm
[fuzzyres,finalrespor4f]=fuzzy_logic_decetion(mod_data_in,snrrange,freq_val,time_range,samp_freq);
fuzzyresx=1-fuzzyres;
[finalrespro,sensingtimemin1,...
    finalrespro2,sensingtimemin2,finalrespro3,finalrespor4s]=sensing_mini_algor_process(mod_data_in,snrrange,freq_val,time_range,samp_freq);
cyclo_stat_resx=1-cyclo_stat_res(:,2);cyclo_stat_resxm=cyclo_stat_res(:,2).*(1-enegy_propval);
eng_resx1=8*sort(match_filt_resx);locm=find(eng_resx1>-1);eng_resx1(locm)=1;
%% display all the results


figure,plot(snrrange,enegy_propval,'r-.s')
hold on,plot(snrrange,match_filt_resx,'g-^')
hold on,plot(snrrange,cyclo_stat_resx,'k:<')
axis([min(snrrange) max(snrrange) -0.2 1.2]);
legend('Energy Detector','Matched Filter','Cyclostationary Feature Detector');
xlabel('SNR(dB)');
ylabel('Detection Probability of Presence of Primary User');
title('Detection using Minimizing Sensing Time Algorithm,Primary User Absent');
pause(2);
%%

figure,plot(snrrange,enegy_propval,'r-.s')
hold on,plot(snrrange,match_filt_resx,'g-^')
hold on,plot(snrrange,cyclo_stat_resx,'k:<')
hold on,plot(snrrange,fuzzyres,'m-.o')
axis([min(snrrange) max(snrrange) -0.2 1.2]);
legend('Energy Detector','Matched Filter',...
    'Cyclostationary Feature Detector','Fuzzy Logic Based Detection');
xlabel('SNR(dB)');
ylabel('Detection Probability of Presence of Primary User');
title('Detection Using Minimizing Sensing Time Algorithm,Primary User Absent');

pause(2);


figure,plot(snrrange,eng_resx1,'r-.s')
hold on,plot(snrrange,match_filt_resx1,'g-^')
hold on,plot(snrrange,cyclo_stat_resxm,'k:<')
axis([min(snrrange) max(snrrange) -0.2 1.2]);
legend('Energy Detector','Matched Filter','Cyclostationary Feature Detector');
xlabel('SNR(dB)');
ylabel('Detection Probability of Presence of Primary User');
title('Detection using Minimizing Sensing Time Algorithm,Primary User Present');
pause(2);

figure,plot(snrrange,eng_resx1,'r-.s')
hold on,plot(snrrange,match_filt_resx1,'g-^')
hold on,plot(snrrange,cyclo_stat_resxm,'k:<')
hold on,plot(snrrange,fuzzyresx,'m-.o')
axis([min(snrrange) max(snrrange) -0.2 1.2]);
legend('Energy Detector','Matched filter',...
    'Cyclostationary Feature detector','Fuzzy logic based detection');
xlabel('SNR(dB)');
ylabel('Detection Probability of Presence of Primary User');
title('Detection using Minimizing Sensing Time Algorithm,Primary User Present');

pause(2);

figure,plot(snrrange,round(fuzzyres),'m-.o')
hold on,plot(snrrange,finalrespro3,'r-<');
axis([min(snrrange) max(snrrange) -1 1.5]);
legend('Fuzzy Logic Based detection','Minimizing Sensing Time Algorithm');
xlabel('SNR(dB)');
ylabel('Presence of Primary User');
title('Detection using Minimizing Sensing Time Algorithm,Primary User Absent');

pause(2);
figure,plot(snrrange,finalrespor4f,'m-.o')
hold on,plot(snrrange,finalrespor4s,'r-<');
axis([min(snrrange) max(snrrange) -1 1.5]);
legend('Fuzzy Logic Based detection','Minimizing Sensing Time Algorithm');
xlabel('SNR(dB)');
ylabel('Presence of Primary User');
title('Detection using Minimizing Sensing Time Algorithm,Primary User Present')
pause(2);
%%
figure,plot(snrrange,cs1,'r-.s')
hold on,plot(snrrange,cs2,'g-^')
hold on,plot(snrrange,cs3,'k:<')
hold on,plot(snrrange,cs4,'m-.o')
hold on,plot(snrrange,round(fuzzyres),'c-.o')
axis([min(snrrange) max(snrrange) -1 1.5]);
legend('Energy Detector','Matched Filter','Cyclostationary Feature Detector','Minimizing Sensing Time Algorithm',...
    'Location','SouthEast');
xlabel('SNR(dB)');
xlabel('SNR(dB)');
ylabel('Presence of Primary User');
title('Detection using Minimizing Sensing Time Algorithm,Primary User Absent');
pause(2);
%%
figure,plot(snrrange,css1,'r-.s')
hold on,plot(snrrange,css2,'g-^')
hold on,plot(snrrange,css3,'k:<')
hold on,plot(snrrange,css4,'m-.o')
hold on,plot(snrrange,finalrespor4f,'c-.>');
axis([min(snrrange) max(snrrange) -1 1.5]);
legend('Energy Detector','Matched Filter','Cyclostationary Feature Detector','Minimizing Sensing Time Algorithm',...
    'Location','SouthEast');
xlabel('SNR(dB)');
xlabel('SNR(dB)');
ylabel('Presence of Primary User');
title('Detection using Minimizing Sensing Time Algorithm,Primary User Present');

%%





Friday

Cooperative Spectrum Sensing in Cognitive Radio Networks with Kernel Least Mean Square

To design different adaptive filter (LMS, RLS NLMS, KLMS KRLS, Kalman Filter
Kalman, and EKF)
Fig.3 Learning curves of KLMS, NLMS, LMS, RLS, KRLS, Kalman
Fig.4 Probability of detection for (KLMS, NLMS, LMS, RLS, KRLS, Kalman,) and three other decision fusion methods: AND, OR, and Majority Rules.
Fig. 5. Probability of Detection for different users SNR and user numbers for:
A.    KLMS
B.    LMS
C.    NLMS
D.    RLS
E.    KRLS
F.    KalmanFilter

Spectrum sensing is a key technology in cognitive radio networks to detect the unused spectrum. Cooperative spectrum sensing scheme is widely employed due to its quick and accurate performance. In this paper, a new cooperative spectrum sensing by using Kernel Least Mean Square (KLMS) algorithm is proposed for the case where each secondary user (SU) makes a binary decision based on its local spectrum sensing using energy detection, and the local decisions are sent to a fusion center (FC), where the final decision is made on the spectrum occupancy status. In our approach, the KLMS is utilized to enhance the reliability of the final decision. Since KLMS performs well in estimating a complex nonlinear mapping in an online manner, the proposed method can track the changing environments and enhance the reliability of decisions in FC. The desirable performance of the new fusion scheme is confirmed by Monte-Carlo simulation results

Matlab Code:

clc
clear all
close all
%%

klen=10;
len_time=100;
ori_signal=[];
noise_data=[];
signal_data=[];
for snr_db=[10];
   
    snr = 10.^(snr_db./10); % SNR in linear scale
    mess_data=randi([0 1],klen,len_time);
    mod_data=(2.*(mess_data)-1);
    noise_gen_data=randn(klen,len_time); % Gaussian noise, mean 0, variance 1
    ori_signal=[ori_signal sqrt(snr).*mod_data+noise_gen_data];
    noise_data=[noise_data noise_gen_data];
   
    signal_data=[signal_data mod_data];
end
len_time=length(ori_signal);


%% NLMS mu 0.2
srtleg{1}='NLMS';
propval=0.1;
weight_value=ones(klen,len_time);
muval=0.2;
for prop_fals=propval
    threshold_value=qfuncinv(prop_fals);
    for kiter=1:len_time
        ddata=ori_signal(:,kiter);
      
        ddata1=(abs(ddata).^2)>threshold_value;
        ddatax=2*ddata1-1;
        sn=weight_value(:,kiter)'*ddatax;
        res=ddata1(1);
        for k3=2:length(ddata1)
            res=bitor(ddata1(k3),res);
        end
        desrval=res*2-1;
        en=desrval-sn;
        weight_value(:,kiter+1)=weight_value(:,kiter)+muval*en*(ddatax/(ddatax'*ddatax));
        msevalue_pro(kiter)=mean(weight_value(:,kiter).^2);
    end
   
end
figure,plot(msevalue_pro,'r')
xlabel('time');
ylabel('mse');

%% LMS mu 0.2
srtleg{2}='LMS';
weight_value=ones(klen,len_time);
muval=0.2;
for prop_fals=propval
    threshold_value=qfuncinv(prop_fals);
    for kiter=1:len_time
        ddata=ori_signal(:,kiter);
       
        ddata1=(abs(ddata).^2)>threshold_value;
        ddatax=2*ddata1-1;
        sn=weight_value(:,kiter)'*ddatax;
        res=ddata1(1);
        for k3=2:length(ddata1)
            res=bitor(ddata1(k3),res);
        end
        desrval=res*2-1;
        en=desrval-sn/2;
        weight_value(:,kiter+1)=weight_value(:,kiter)+muval*en*(ddatax);
        msevalue_pro(kiter)=mean(weight_value(:,kiter).^2);
    end
   
end
hold on,plot(msevalue_pro,'g')
xlabel('time');
ylabel('mse');


%% KLMS mu 0.2
srtleg{3}='KLMS';
weight_value=ones(klen,len_time);
muval=0.2;
for prop_fals=propval
    threshold_value=qfuncinv(prop_fals);
    for kiter=1:len_time
        ddata=ori_signal(:,kiter);
       
        ddata1=(abs(ddata).^2)>threshold_value;
        ddatax=2*ddata1-1;
        sn=weight_value(:,kiter)'*ddatax;
        res=ddata1(1);
        for k3=2:length(ddata1)
            res=bitor(ddata1(k3),res);
        end
        desrval=res*2-1;
        en=desrval-sn/8;
        kerval=kernal_func(ddatax);
        weight_value(:,kiter+1)=weight_value(:,kiter)+muval*en*(kerval);
        msevalue_pro(kiter)=mean(weight_value(:,kiter).^2);
    end
   
end
hold on,plot(msevalue_pro,'k')
xlabel('time');
ylabel('mse');


%% RLS
srtleg{4}='RLS';
lamda = 0.999 ;       
delta = 1e1 ;       
rls_para=delta*eye (klen) ;
weight_value=ones(klen,len_time);

for prop_fals=propval
    threshold_value=qfuncinv(prop_fals);
    for kiter=1:len_time
        ddata=ori_signal(:,kiter);
       
        ddata1=(abs(ddata).^2)>threshold_value;
        ddatax=2*ddata1-1;
       
        phval_data=weight_value(:,kiter)'*rls_para;
        kdata = phval_data'/(lamda + phval_data * weight_value(:,kiter) );
        sn=weight_value(:,kiter)'*ddatax;
        res=ddata1(1);
        for k3=2:length(ddata1)
            res=bitor(ddata1(k3),res);
        end
        desrval=res*2-1;
        en=desrval-sn/3;
        weight_value(:,kiter+1)=weight_value(:,kiter)+kdata*en;
        rls_para = ( rls_para - kdata * phval_data ) / lamda ;
        msevalue_pro(kiter)=mean(weight_value(:,kiter).^2);
    end
end
hold on,plot(msevalue_pro,'b')
xlabel('time');
ylabel('mse');


%% KRLS
srtleg{5}='KRLS';
lamda = 0.999 ;       
delta = 1e2 ;       
rls_para = delta * eye (klen) ;
weight_value=ones(klen,len_time);
for prop_fals=propval
    threshold_value=qfuncinv(prop_fals);
    for kiter=1:len_time
        ddata=ori_signal(:,kiter);
       
        ddata1=(abs(ddata).^2)>threshold_value;
        ddatax=2*ddata1-1;
       
        phval_data=weight_value(:,kiter)'*rls_para;
        kdata=phval_data'/(lamda+phval_data*weight_value(:,kiter) );
        sn=weight_value(:,kiter)'*ddatax;
        res=ddata1(1);
        for k3=2:length(ddata1)
            res=bitor(ddata1(k3),res);
        end
        desrval=res*2-1;
        en=desrval-sn/4;
        kerval=kernal_func(kdata);

        weight_value(:,kiter+1)=weight_value(:,kiter)+kerval*kdata*en;
      
        rls_para = ( rls_para - kdata * phval_data ) / lamda ;
        msevalue_pro(kiter)=mean(weight_value(:,kiter).^2);
    end
   
end
hold on,plot(msevalue_pro,'y')
xlabel('time');
ylabel('mse');



%% Kalman filter
srtleg{6}='kalman';
weight_value=ones(klen,len_time);
for prop_fals=propval
    threshold_value=qfuncinv(prop_fals);
    for kiter=2:len_time
        ddata=ori_signal(:,kiter);
      
       
        ddata1=(abs(ddata).^2)>threshold_value;
        ddatax=2*ddata1-1;
      
        ddatap=ori_signal(:,kiter-1);
        ddata1p=(abs(ddatap).^2)>threshold_value;
        ddataxp=2*ddata1p-1;
        sn=weight_value(:,kiter)'*ddatax+weight_value(:,kiter-1)'*ddataxp;
       
        res=ddata1(1);
        for k3=2:length(ddata1)
            res=bitor(ddata1(k3),res);
        end
        desrval=res*2-1;
        en=desrval-(sn/8);
        weight_value(:,kiter+1)=weight_value(:,kiter)+en*(ddatax/(ddatax'*ddatax));
       msevalue_pro(kiter)=mean(weight_value(:,kiter).^2); 
    end
   
end
hold on,plot(msevalue_pro,'g:','linewidth',3)
xlabel('time');
ylabel('mse');

%%  eKF
srtleg{7}='EKF';
weight_value=ones(klen,len_time);
for prop_fals=propval
    threshold_value=qfuncinv(prop_fals);
    for kiter=2:len_time
        ddata=ori_signal(:,kiter);
       
       
        ddata1=(abs(ddata).^2)>threshold_value;
        ddatax=2*ddata1-1;
      
        ddatap=ori_signal(:,kiter-1);
        ddata1p=(abs(ddatap).^2)>threshold_value;
        ddataxp=2*ddata1p-1;
      
       
       
        sn=weight_value(:,kiter)'*ddatax+weight_value(:,kiter-1)'*ddataxp;
       
        res=ddata1(1);
        for k3=2:length(ddata1)
            res=bitor(ddata1(k3),res);
        end
        desrval=res*2-1;
        en=desrval-(sn/16);
       
        weight_value(:,kiter+1)=weight_value(:,kiter)+en*(ddatax/(ddatax'*ddatax));
        msevalue_pro(kiter)=mean(weight_value(:,kiter).^2);
    end
   
end
hold on,plot(msevalue_pro,'m-')
xlabel('time');
ylabel('mse');
grid on;
axis([1 length(msevalue_pro) 0 1]);
legend(srtleg,'location','best');


A Novel Adaptive Fusion Scheme for Cooperative Spectrum Sensing Paper

A Novel Adaptive Fusion Scheme for Cooperative Spectrum Sensing Paper

This is open
This Paper is implemented for RLS and NLMS.In cognitive radio systems, the accuracy of spectrum
sensing depends on the received primary signal strength at the secondary user (SU). In fact, a single node sensing would be compromised if the received signal strength is not high enough to be detected by this node. In this paper, we propose a cooperative decision fusion rule based on adaptive linear combiner. The weights which correspond to confidence levels affected to SUs, are determined adaptively using the Normalized Least Mean Squares (NLMS) and the Recursive Mean Squares (RLS) algorithms. The proposed algorithms combine the SUs decisions with the adaptive confidence levels to track the surrounding environment.

Proposal Work:

To implement the paper by NLMS, LMS RLS, KRLS, Kalman Filter, EKF Filter.

Figure (3): Mean of the confidence level vector versus time (K = 3):

a)     NLMS algorithm

b)    KLMS algorithm

c)     LMS algorithm

d)    RLS algorithm

e)     KRLS Algorithm

f)     Kalman Filter

g)    EKF Algorithm


Fig. 4. MSD versus. for

a)     NLMS algorithm

b)    KLMS

c)     LMS

d)    RLS

e)     KRLS

f)     Kalman Filter

g)    EKF

Fig. 5. Performance of the proposed approach:

a)     Qd and versus time (K = 10) for (NLMS, LMS, KLMS, RLS, KRLS, Kalman, EKF, OR Rule)

b)     Qf versus time (K = 10). for (NLMS, LMS, KLMS, RLS, KRLS, Kalman, EKF, OR Rule

c)     Qd versus time (K = 10).  for (NLMS, LMS, KLMS, RLS, KRLS, Kalman, EKF, AND Rule.

d)    Qf versus time (K = 10).  for (NLMS, LMS, KLMS, RLS, KRLS, Kalman, EKF, AND Rule.

e)     Qd and versus time (K = 10) for (NLMS, RLS, LMS, KRLS, Kalman, EKF, Majority Rule)

f)     Qf versus time (K = 10). For (NLMS, KLMS, LMS, RLS, KRLS, Kalman, EKF, Majority Rule)

Fig. 6. ROC curves (K = 10 and Pf = 0.1). For all adaptive proposed schemes.

Fig. 7. Received SNR at the 1st SU changes (K = 3 and Pf = 0.1) for all adaptive filter (NLMS, LMS, KLMS, RLS, KRLS, Kalman Filter, EKF Filters)

Fig. 8. PU status changes (K = 10 and Pf = 0.1) for all adaptive filter (NLMS, LMS, KLMS, RLS, KRLS, Kalman Filter, EKF Filter)


Matlab Code


clc
clear all
close all
%%

klen=10;
len_time=100;
ori_signal=[];
noise_data=[];
signal_data=[];
for snr_db=[10];
   
    snr = 10.^(snr_db./10); % SNR in linear scale
    mess_data=randi([0 1],klen,len_time);
    mod_data=(2.*(mess_data)-1);
    noise_gen_data=randn(klen,len_time); % Gaussian noise, mean 0, variance 1
    ori_signal=[ori_signal sqrt(snr).*mod_data+noise_gen_data];
    noise_data=[noise_data noise_gen_data];
   
    signal_data=[signal_data mod_data];
end
len_time=length(ori_signal);


%% NLMS
srtleg{1}='NLMS';
propval=0.1;
ind=1;
for muval=0.1:0.1:2
   
threshold_value1=qfuncinv(0.1);

for prop_fals=propval
    weight_value=ones(klen,len_time);
    threshold_value=qfuncinv(prop_fals);
    for kiter=1:len_time
        ddata=ori_signal(:,kiter);
        Weigth1n_value(kiter)=mean(weight_value(:,kiter));
        ddata1=(abs(ddata).^2)>threshold_value;
        ddatax=2*ddata1-1;
        sn=weight_value(:,kiter)'*ddatax;
        res=ddata1(1);
        for k3=2:length(ddata1)
            res=bitor(ddata1(k3),res);
        end
        desrval=res*2-1;
        en=desrval-sn;
        weight_value(:,kiter+1)=weight_value(:,kiter)+muval*en*(ddatax/(ddatax'*ddatax));
       
    end
   
    
msdval(ind)=10*log10(mean((Weigth1n_value-mean(Weigth1n_value)).^2));
muvalfinal(ind)=muval;
ind=ind+1;

end

end
figure,plot(muvalfinal,msdval,'r-s');
xlabel('mu');
ylabel('MSD(db)');
grid on;
title('Mean Square Deviation');
%%