Skip to content

Commit

Permalink
add different Modulation, update code
Browse files Browse the repository at this point in the history
  • Loading branch information
achilletIrisa committed Feb 28, 2024
1 parent 20fd42c commit c0b50fa
Show file tree
Hide file tree
Showing 17 changed files with 576 additions and 259 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
DigitalComm = "a7b11256-881b-11e9-3aff-ff4a76f1bfae"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
Flatten = "4c728ea3-d9ee-5c9a-9642-b6f7d7dc04fa"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
Infiltrator = "5903a43b-9cc3-4c30-8d17-598619ec4e9b"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Expand Down
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
# RiFyFi
# RiFyFi.jl

[![Build Status](https://github.com/achilletIrisa/RiFyFi.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/achilletIrisa/RiFyFi.jl/actions/workflows/CI.yml?query=branch%3Amain)

[introduction.pdf](https://github.com/JuliaTelecom/Rifyfi.jl/files/13974266/introduction.pdf)

RiFyFi is a framework for Radio Frequency Fingerprint Identification. RFF is a unique signature created in the emitter transmission chain by the hardware impairments. These impairments may be used as a secure identifier as they cannot be easily replicated for spoofing purposes. In recent years, the RFF identification relies mainly on Deep Learning (DL), and large databases are consequently needed to improve identification in different environmental conditions. RiFyFi is introduced to propose a framework combine with a virtual database to explore the RFF identification. Different transmission scenarios are modeled such as the data type (being a preamble or a payload) and the data size.

RiFyFi is composed of different subpackage
- RiFyFi_VDG : The Virtual Database Generator
- RiFyFi_IdF : Package for training and testing network
- Augmentation : Package used for data augmentation
- Results : Package to create some confusion matrix or F1 score evolution in function of time.

## Protocol to use RiFyFi with Julia

Insatall Julia (here develop with 1.8.5)
Create a folders
Download or clone the project with git clone
Going in Rifyfi.jl
Open Julia terminal
Download or clone the project with: git clone https://github.com/JuliaTelecom/Rifyfi.jl
Going in Rifyfi.jl folders
Open a Julia terminal
Activate the project ] activate .
Instantiate the project with ] instantiate

Then you can you the script script_example.jl, in the Julia Terminal :
include("src/script_exemple.jl")


Then you can use RiFyFi in two manners:
- Creating random parameter values for impairments
- Define the value of the impairments parameters with scenario file
Expand Down
22 changes: 12 additions & 10 deletions src/Results/src/Prod_ConfusionMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,39 @@ end


""" Fonction qui plot la matrice de confusion en format csv \n
filename = .pkl file
filename = .pkl
file
txs,rxs,days,equalized = param for test with 2 for equalized
rxsnn,daysnn = param to choose to CNN
ChunSize = 256
dataAug = "sans" or "OfflineV1"
"""

function Confusion_Matrix_CSV(Param_Data,Param_Network,savepathbson="")
function Confusion_Matrix_CSV(Param_Data,Param_Network,savepathbson="",Param_Data_test=Param_Data)
if Param_Network.Train_args.use_cuda ==true
hardware1 = "GPU"
else
hardware1 ="CPU"
end
if savepathbson == ""
if Param_Data.Augmentation_Value.augmentationType == "No_channel"
savepathbson = "run/Synth/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)_$(Param_Network.Networkname)/$(Param_Data.E)_$(Param_Data.S)/$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.nameModel)/$(hardware1)"
savepath_model = "run/Synth/$(Param_Data.Modulation)/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)_$(Param_Network.Networkname)/$(Param_Data.E)_$(Param_Data.S)/$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.nameModel)/$(hardware1)"
else
savepathbson = "run/Synth/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)_$(Param_Network.Networkname)/$(Param_Data.E)_$(Param_Data.S)/$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.nameModel)_$(Param_Data.Augmentation_Value.Channel)_$(Param_Data.Augmentation_Value.Channel_Test)_nbAugment_$(Param_Data.Augmentation_Value.nb_Augment)/$(hardware1)"
savepath_model = "run/Synth/$(Param_Data.Modulation)/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)_$(Param_Network.Networkname)/$(Param_Data.E)_$(Param_Data.S)/$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.nameModel)_$(Param_Data.Augmentation_Value.Channel)_$(Param_Data.Augmentation_Value.Channel_Test)_nbAugment_$(Param_Data.Augmentation_Value.nb_Augment)/$(hardware1)"
end
end

allAcc = Float64[]

res =RiFyFi_IdF.loadCNN("$(savepathbson)/model_seed_$(Param_Network.Seed_Network)_dr$(Param_Network.Train_args.dr).bson")
res = RiFyFi_IdF.loadCNN("$(savepath_model)/model_seed_$(Param_Network.Seed_Network)_dr$(Param_Network.Train_args.dr)_$(Param_Data.Modulation).bson")
#res =RiFyFi_IdF.loadCNN("$(savepath_model)/model_new.bson")

model = res.model
testmode!(model, true) # We are in test mode, with no dropout
(moy,std_val) = (nothing,nothing)
allAccuracy = Float64[]

(_,_,X_test,Y_test) =loadCSV_Synthetic(Param_Data)
(_,_,X_test,Y_test) =loadCSV_Synthetic(Param_Data_test)


if Param_Network.Train_args.use_cuda
Expand All @@ -98,13 +100,13 @@ function Confusion_Matrix_CSV(Param_Data,Param_Network,savepathbson="")
confMatrix = confusionMatrix(l̂,l,Param_Data.nbTx)
plt = plotConfusionMatrix(confMatrix )

savepath ="Results/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)_$(Param_Network.Networkname)/$(Param_Data.E)_$(Param_Data.S)"
!ispath(savepath) && mkpath(savepath)
savepath_result ="Results/$(Param_Data.Modulation)/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)_$(Param_Network.Networkname)/$(Param_Data.E)_$(Param_Data.S)"
!ispath(savepath_result) && mkpath(savepath_result)
Temp=zeros(1,Param_Data.nbTx)
if Param_Data.Augmentation_Value.augmentationType == "No_channel"
file="$(savepath)/confMatrix_$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.name)_seed_$(Param_Network.Seed_Network).csv"
file="$(savepath_result)/confMatrix_$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.name)_seed_$(Param_Network.Seed_Network).csv"
else
file="$(savepath)/confMatrix_$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.name)_$(Param_Data.Augmentation_Value.Channel)_$(Param_Data.Augmentation_Value.Channel_Test)_nbAugment_$(Param_Data.Augmentation_Value.nb_Augment)_seed_$(Param_Network.Seed_Network).csv"
file="$(savepath_result)/confMatrix_$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.name)_$(Param_Data.Augmentation_Value.Channel)_$(Param_Data.Augmentation_Value.Channel_Test)_nbAugment_$(Param_Data.Augmentation_Value.nb_Augment)_seed_$(Param_Network.Seed_Network).csv"
end
open(file,"w") do io
for i in 0:size(confMatrix,1)-1
Expand Down
14 changes: 7 additions & 7 deletions src/Results/src/Results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using .RiFyFi_VDG
include("../../RiFyFi_IdF/src/RiFyFi_IdF.jl")
using .RiFyFi_IdF

function main(Param_Data,Param_Network,Type_Resuts,Table_Seed_Network,savepathbson)
function main(Param_Data,Param_Network,Type_Resuts,Table_Seed_Network,savepathbson,Param_Data_test)

if Type_Resuts == "F1_score"
F1_score_Synth(Param_Data,Param_Network,Table_Seed_Network,savepathbson)
Expand All @@ -39,7 +39,7 @@ function main(Param_Data,Param_Network,Type_Resuts,Table_Seed_Network,savepathbs
Compute_mean(Param_Data,Param_Network,nameSituation,Table_Seed_Network)

elseif Type_Resuts == "Confusion_Matrix"
Confusion_Matrix_CSV(Param_Data,Param_Network,savepathbson )
Confusion_Matrix_CSV(Param_Data,Param_Network,savepathbson,Param_Data_test )

end

Expand All @@ -55,9 +55,9 @@ function F1_score_Synth(Param_Data,Param_Network,Table_Seed_Network,savepathbson
end
if savepathbson == ""
if Param_Data.Augmentation_Value.augmentationType == "No_channel"
savepathbson = "run/Synth/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)_$(Param_Network.Networkname)/$(Param_Data.E)_$(Param_Data.S)/$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.nameModel)/$(hardware1)"
savepathbson = "run/Synth/$(Param_Data.Modulation)/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)_$(Param_Network.Networkname)/$(Param_Data.E)_$(Param_Data.S)/$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.nameModel)/$(hardware1)"
else
savepathbson = "run/Synth/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)_$(Param_Network.Networkname)/$(Param_Data.E)_$(Param_Data.S)/$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.nameModel)_$(Param_Data.Augmentation_Value.Channel)_$(Param_Data.Augmentation_Value.Channel_Test)_nbAugment_$(Param_Data.Augmentation_Value.nb_Augment)/$(hardware1)"
savepathbson = "run/Synth/$(Param_Data.Modulation)/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)_$(Param_Network.Networkname)/$(Param_Data.E)_$(Param_Data.S)/$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.nameModel)_$(Param_Data.Augmentation_Value.Channel)_$(Param_Data.Augmentation_Value.Channel_Test)_nbAugment_$(Param_Data.Augmentation_Value.nb_Augment)/$(hardware1)"
end
end
if Param_Data.Augmentation_Value.augmentationType == "No_channel"
Expand Down Expand Up @@ -85,7 +85,7 @@ function F1_score_Synth(Param_Data,Param_Network,Table_Seed_Network,savepathbson
for i =1 :1: size(Table_Seed_Network,1)
Param_Network.Seed_Network= Table_Seed_Network[i]
name = savename
Scenario ="$(savepathbson)/F1_Score_$(hardware1)_seed_$(Param_Network.Seed_Network)_dr$(Param_Network.Train_args.dr).csv"
Scenario ="$(savepathbson)/F1_Score_$(hardware1)_seed_$(Param_Network.Seed_Network)_dr$(Param_Network.Train_args.dr)_$(Param_Data.Modulation).csv"
delim=';'
nameBase = split(Scenario,".")[1]
# ----------------------------------------------------
Expand All @@ -104,7 +104,7 @@ function F1_score_Synth(Param_Data,Param_Network,Table_Seed_Network,savepathbson
@pgf push!(a, LegendEntry("Seed $(i)")) # Train)

end
pgfsave("$(savepathbson)/F1_Score_$(savename).tex",a)
pgfsave("$(savepathbson)/F1_Score_$(savename)_$(Param_Data.Modulation).tex",a)

end

Expand All @@ -113,7 +113,7 @@ end

function Compute_mean(Param_Data,Param_Network,nameSituation,Table_Seed_Network)

savepath = "../My_RFFI_Syst/run/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)_$(Param_Network.Networkname)/$(Param_Data.E)_$(Param_Data.S)"
savepath = "run/$(Param_Data.Modulation)/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)_$(Param_Network.Networkname)/$(Param_Data.E)_$(Param_Data.S)"
if Param_Network.Train_args.use_cuda ==true
hardware1 = "GPU"
else
Expand Down
21 changes: 14 additions & 7 deletions src/RiFyFi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ using .RiFyFi_VDG
include("RiFyFi_IdF/src/RiFyFi_IdF.jl")
using .RiFyFi_IdF

include("Augmentation/src/Augmentation.jl")
using .Augmentation

include("Results/src/Results.jl")
using .Results


# ----------------------------------------------------
# --- Loading utility functions
# ----------------------------------------------------
Expand Down Expand Up @@ -60,22 +67,22 @@ function main(Param_Data,Param_Network)

(dataTrain,dataTest) = init(Param_Data,Param_Network)
if Param_Data.Augmentation_Value.augmentationType == "No_channel"
savepath = "run/Synth/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)_$(Param_Network.Networkname)/$(Param_Data.E)_$(Param_Data.S)/$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.nameModel)/$(hardware)"
savepath_model = "run/Synth/$(Param_Data.Modulation)/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)_$(Param_Network.Networkname)/$(Param_Data.E)_$(Param_Data.S)/$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.nameModel)/$(hardware)"
else
savepath = "run/Synth/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)_$(Param_Network.Networkname)/$(Param_Data.E)_$(Param_Data.S)/$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.nameModel)_$(Param_Data.Augmentation_Value.Channel)_$(Param_Data.Augmentation_Value.Channel_Test)_nbAugment_$(Param_Data.Augmentation_Value.nb_Augment)/$(hardware)"
savepath_model = "run/Synth/$(Param_Data.Modulation)/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)_$(Param_Network.Networkname)/$(Param_Data.E)_$(Param_Data.S)/$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.nameModel)_$(Param_Data.Augmentation_Value.Channel)_$(Param_Data.Augmentation_Value.Channel_Test)_nbAugment_$(Param_Data.Augmentation_Value.nb_Augment)/$(hardware)"
end
!ispath(savepath) && mkpath(savepath)
@infiltrate
(model,trainLoss,trainAcc,testLoss,testAcc,args) = customTrain!(dataTrain,dataTest,savepath,Param_Network)
!ispath(savepath_model) && mkpath(savepath_model)

(model,trainLoss,trainAcc,testLoss,testAcc,args) = customTrain!(dataTrain,dataTest,savepath_model,Param_Network,Param_Data.Modulation)
# ----------------------------------------------------
# --- Saving model
# ----------------------------------------------------
modelpath = joinpath(savepath, "model_seed_$(Param_Network.Seed_Network)_dr$(Param_Network.Train_args.dr).bson")
modelpath = joinpath(savepath_model, "model_seed_$(Param_Network.Seed_Network)_dr$(Param_Network.Train_args.dr)_$(Param_Data.Modulation).bson")
nbEpochs = args.epochs
BSON.@save modelpath model nbEpochs trainLoss trainAcc testLoss testAcc args
testAugmented_acc =0
testAugmented_loss=0
return (savepath,model,trainLoss,trainAcc,testLoss,testAcc,testAugmented_loss,testAugmented_acc)
return (savepath_model,model,trainLoss,trainAcc,testLoss,testAcc,testAugmented_loss,testAugmented_acc)
end


Expand Down
5 changes: 5 additions & 0 deletions src/RiFyFi_IdF/src/RiFyFi_IdF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,16 @@ end

function loadCNN(cnnPath)
# --- Loading data
# dict = BSON.parse(cnnPath)

dict = BSON.load(cnnPath,@__MODULE__)
# --- Exporting variables
model = dict[:model]
testAcc = dict[:testAcc]
trainAcc = dict[:trainAcc]
testLoss = dict[:testLoss]
trainLoss = dict[:trainLoss]

#=moy = 0
std = 1
try
Expand Down Expand Up @@ -318,6 +321,8 @@ export Network_struct
export Args
export Args_construct



end


4 changes: 2 additions & 2 deletions src/RiFyFi_IdF/src/customTrain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ end



function customTrain!(dataTrain,dataTest,savepath,Param_Network)
function customTrain!(dataTrain,dataTest,savepath_model,Param_Network,Modulation)
# ----------------------------------------------------
# --- CPU or GPU
# ----------------------------------------------------
Expand Down Expand Up @@ -151,7 +151,7 @@ function customTrain!(dataTrain,dataTest,savepath,Param_Network)
# Timings are calculated per eopch, we want complete time
Param_Network.Train_args.timings = cumsum(Param_Network.Train_args.timings;dims=1)
# Write timings and accuracy in a file
open("$(savepath)/F1_Score_$(DeviceName)_seed_$(Param_Network.Seed_Network)_dr$(Param_Network.Train_args.dr).csv","w") do io
open("$(savepath_model)/F1_Score_$(DeviceName)_seed_$(Param_Network.Seed_Network)_dr$(Param_Network.Train_args.dr)_$(Modulation).csv","w") do io
arr = [Param_Network.Train_args.timings[1:epoch] trainf1 testf1 trainLoss testLoss]
writedlm(io,round.(arr;digits=4),';')
end
Expand Down
Binary file added src/RiFyFi_VDG/PA_memory_models.mat
Binary file not shown.
Loading

0 comments on commit c0b50fa

Please sign in to comment.