clc;
clear;
close all;
Nu = 20; % Number Of Primary Users
T = 200; % Number of frames
N = 256; % FFT length
w = rectwin(N); % Window function
Tb = 0.4e-3; % Bit duration
Ts = 1e-6/128; % Sampling time
n_bits = 5;
no_of_obs = n_bits;
percentage_of_occupancy = 0.5; % Only 30 % of the Primary users are using channel
SNR = -20;
pf = 0.001; % Probability of false Alarm
dt = ones(1,round(Tb/Ts));
t = Ts:Ts:Ts*round(n_bits*Tb/Ts);
f = (20:1:20+((Nu-1)*1))*1e6; % band gap = 1 MHz
carr = zeros(Nu,round(n_bits*Tb/Ts));
% Generate Carrier for each user
for k = 1:Nu
carr(k,:) = exp(1j*2*pi*f(1,k)*t);
end
% Generate Window function for each user
for k = 1:T
W(k,:) = w;
end
tt = rand(Nu,n_bits);
PU_status = zeros(size(tt));
Sp = (sum(dt.^2)*Nu)/length(dt);
No = Sp*10^(-0.1*SNR);
Np = sqrt(No/2);
data = double(rand(Nu,n_bits)>0.5);
for k = 1:n_bits
PU_status(:,k) = double(tt(:,k) < percentage_of_occupancy);
end
% PU_status = ones(size(tt));
data_1 = [];
for k = 1:Nu
temp = [];
for p = 1:n_bits
if data(k,p) == 1
temp = [temp PU_status(k,p)*dt];
else
temp = [temp -PU_status(k,p)*dt];
end
end
data_1(k,:) = temp;
end
clear temp;
data_up = zeros(size(carr));
% data_ch = zeros(size(carr));
for k = 1:Nu
data_up(k,:) = data_1(k,:).*carr(k,:);
% data_ch(k,:) = filter([1 randn(1,5)],1,data_up(k,:));
end
data_rx = sum(data_up,1) + (Np*randn(1,length(data_up)));
% no_of_obs = 1;
temp = reshape(data_rx(1,1:no_of_obs*N*T),N*T,no_of_obs)';
for r = 1:no_of_obs
temp1 = reshape(temp(r,:),N,T)'; % break the received sampled signal into T frames of N samples each
P = abs(fft(temp1.*W,N,2)).^2; % Compute PSD
P_avg = sum(P,1)/T; % Average power
Pm = (2/(N+2))*sum(P_avg(1,1:round(N/2)+1)); % Mean Power
Rk1 = P_avg/Pm; % Decision Parameter
th =chi2inv(1-pf,Tb/Ts)*Ts/Tb; % Threshold
% th = (max(Rk1) + min(Rk1))/2;
status(r,:) = Rk1(1,41:2:40 + (2*Nu) - 1) > th;
% status1(r,:) = Rk1(1,41:2:79) > th_2;
thh = ones(1,length(status))*th;
figure(1)
subplot(no_of_obs,1,r)
stem(f*1e-6,status(r,:),'*r')
hold on
stem(f*1e-6,PU_status(:,r),'k')
xlabel(' Frequency in MHz');
ylabel(' Availability ');
axis([19 40 -0.5 1.5]);
title(' SNR = -40 dB');
hold off
figure(2)
subplot(no_of_obs,1,r)
stem(f*1e-6,Rk1(1,41:2:40 + (2*Nu) - 1),'*r')
hold on
plot(f*1e-6,thh)
xlabel('Frequency in MHz')
ylabel(' Decision variable r(k) ');
axis([19 40 -0.5 max(Rk1)]);
title(' SNR = -40 dB');
hold off
end
Spectrum sensing using FFT Averaging Ratio (FAR) Algorithm
版权申诉
30 浏览量
2022-03-08
17:11:42
上传
评论
收藏 2KB ZIP 举报
且行好事莫问前程
- 粉丝: 2w+
- 资源: 443
最新资源
- 5G RAN NR TDD单用户峰值吞吐率计算过程.pptx
- 基于Objective-C开发的手势密码解锁和面容解锁(代码简洁高效通俗易懂)+源码+开发文档+源码解析(毕业设计&课程设计)
- LangChain学习之 Question And Answer的操作附带数据文件
- linux常用命令大全.zip
- CATIA入门操作案例-正八边异形带孔凸台绘制,等距点绘制正多边形,凸台绘制
- 大型代码语言模型的项目级提示生成pdf
- 纸片战争The War of paper.sb3
- testedtestedtested
- 基于C语言+STM32开发的智能门锁优秀项目+包含指纹识别、人脸识别、RFID解锁、密码解锁、蓝牙解锁功能+源码+项目解析
- 目标检测-智能零售柜商品检测数据集-5000张图-+对应VOC-COCO-YOLO三种格式标签+数据集划分脚本
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈