Skip to content

Commit

Permalink
update script and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
achilletIrisa committed Jan 25, 2024
1 parent 7fff641 commit 20fd42c
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 167 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,17 @@
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.


The framework will be access here soon.

Create a folders
Download or clone the project with git clone
Going in Rifyfi.jl
Open Julia terminal
Activate the project ] activate .
Instantiate the project with ] instantiate

Then you can use RiFyFi in two manners:
- Creating random parameter values for impairments
- Define the value of the impairments parameters with scenario file



4 changes: 2 additions & 2 deletions src/Augmentation/src/Augmentation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using Random
using DigitalComm
using DSP
using Distributed

using Infiltrator
include("Struct_Augmentation.jl")
export Data_Augmented
export Data_Augmented_construct
Expand Down Expand Up @@ -47,7 +47,7 @@ function Add_diff_Channel_train_test(bigMat, bigLabels, N, channel, ChunkSize, p
subSigAugmented = zeros(ComplexF32,Int(ChunkSize*burstSizeTemp))
subSig = @views sig[ Int((iN-1)*ChunkSize*burstSize) .+ (1:Int(ChunkSize*burstSizeTemp))]
for j = 1 : 1 : pourcentAugment
Random.seed!(seed * iR + j )
Random.seed!(seed * iR + j )
#--- Data augmentation
# First get unique impairment model
σ = choose(snrRange)
Expand Down
6 changes: 3 additions & 3 deletions src/Augmentation/src/Struct_Augmentation.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Base.@kwdef mutable struct Data_Augmented
augmentationType::String = "sans"
augmentationType::String = "No_channel"
Channel::String = "etu"
Channel_Test::String = "etu"
nb_Augment::Int = 1
seed_channel::Int = 12
seed_channel_test::Int = 9999s99999 * 100000000
seed_channel_test::Int = 999999999 * 100000000
burstSize::Int =64
end

Expand All @@ -14,7 +14,7 @@ function Data_Augmented_construct(; kwargs...)
if haskey(kwargs, :augmentationType)
augmentationType = kwargs[:augmentationType]
else
augmentationType="sans"
augmentationType="No_channel"
end

if haskey(kwargs, :Channel)
Expand Down
5 changes: 2 additions & 3 deletions src/Results/src/Prod_ConfusionMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function Confusion_Matrix_CSV(Param_Data,Param_Network,savepathbson="")
hardware1 ="CPU"
end
if savepathbson == ""
if Param_Data.Augmentation_Value.augmentationType == "sans"
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)"
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)"
Expand Down Expand Up @@ -101,7 +101,7 @@ function Confusion_Matrix_CSV(Param_Data,Param_Network,savepathbson="")
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)
Temp=zeros(1,Param_Data.nbTx)
if Param_Data.Augmentation_Value.augmentationType == "sans"
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"
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"
Expand All @@ -123,7 +123,6 @@ function MainPlottingMatrix_Latex(file,E="E2",S="S1",C="C1",Network="AlexNet",RF
header = (["Tx\$_$i\$" for i = 1 : 1 : nbRadioTx])
row_labels = (["TxTrue\$_$i\$" for i = 1 : 1 : nbRadioTx])
row_label_column_title = "\\backslashbox[15mm][]{\\footnotesize True}{\\footnotesize Guess}"
# file="run/ManySig/sans_$(nbRadioTx)_$(ChunkSize)_$(Network)/$(hardware)/confMatrix_$(E)_$(S)_$(C)_$(C_test)_$(RFF).csv"
cellcolor_header = "blue!10!white"

m = latexConfusionMatrix(file;doSave=true,standalone=true,header,row_label_column_title,row_labels,cellcolor_header)
Expand Down
6 changes: 3 additions & 3 deletions src/Results/src/Results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ function F1_score_Synth(Param_Data,Param_Network,Table_Seed_Network,savepathbson
hardware1 ="CPU"
end
if savepathbson == ""
if Param_Data.Augmentation_Value.augmentationType == "sans"
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)"
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)"
end
end
if Param_Data.Augmentation_Value.augmentationType == "sans"
if Param_Data.Augmentation_Value.augmentationType == "No_channel"
savename ="$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.name)"
else
savename ="$(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)"
Expand Down Expand Up @@ -119,7 +119,7 @@ function Compute_mean(Param_Data,Param_Network,nameSituation,Table_Seed_Network)
else
hardware1 ="CPU"
end
if Param_Data.Augmentation_Value.augmentationType == "sans"
if Param_Data.Augmentation_Value.augmentationType == "No_channel"
name= "$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.name)"
else
name ="$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.name)_nbAugment_$(Param_Data.Augmentation_Value.nb_Augment)"
Expand Down
18 changes: 7 additions & 11 deletions src/RiFyFi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export getAccuracy

""" Function that drives the cnn and saves it in .bson\n
Parameters :
- Param_Data type Data_Synth ou Data_WiSig
- Param_Data type Data_Synth
- Param_Network type of Network_struct
"""
function main(Param_Data,Param_Network)
Expand All @@ -59,15 +59,13 @@ function main(Param_Data,Param_Network)
end

(dataTrain,dataTest) = init(Param_Data,Param_Network)
if Param_Data.name== "WiSig"
savepath = "run/WiSig/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)_$(Param_Network.Networkname)/$(Param_Data.txs)_$(Param_Data.rxs)/$(Param_Data.txs)_$(Param_Data.rxs)_$(Param_Data.days)_$(Param_Data.nbSignals)/$(hardware)"
elseif Param_Data.Augmentation_Value.augmentationType == "sans"
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)"
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)"
end
!ispath(savepath) && mkpath(savepath)

@infiltrate
(model,trainLoss,trainAcc,testLoss,testAcc,args) = customTrain!(dataTrain,dataTest,savepath,Param_Network)
# ----------------------------------------------------
# --- Saving model
Expand All @@ -85,7 +83,7 @@ end

""" Function that load Data in Matrix format and initialize the Network
Parameters :
- Param_Data type Data_Synth ou Data_WiSig
- Param_Data type Data_Synth
- Param_Network type of Network_struct
"""
function init(Param_Data,Param_Network)
Expand All @@ -94,11 +92,9 @@ function init(Param_Data,Param_Network)
# ----------------------------------------------------
@info "init"
Random.seed!(Param_Network.Seed_Network)
if Param_Data.name== "WiSig"
(X_train,Y_train,X_test,Y_test)=loadCSV_WiSig(Param_Data)
else
(X_train,Y_train,X_test,Y_test)=loadCSV_Synthetic(Param_Data)
end

(X_train,Y_train,X_test,Y_test)=loadCSV_Synthetic(Param_Data)


# ----------------------------------------------------
# --- Create datasets
Expand Down
26 changes: 25 additions & 1 deletion src/RiFyFi_IdF/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,28 @@
[![Build Status](https://github.com/achillet/RiFyFi_IdF.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/achillet/RiFyFi_IdF.jl/actions/workflows/CI.yml?query=branch%3Amain)


The Module RiFyFi_IdF defines function related to the classification/ Identification Framework particularly based on CNN
The Module RiFyFi_IdF defines function related to the classification/ Identification Framework particularly based on CNN


function initAlexNet(x)
- definition des différentes couche du reseaux
- définition de la crossentropy
return (m,loss)
end


# customTrain.jl

function customTrain!(nn,customLoss,dataTrain,dataTest,savepath;kws...)
- décision GPU ou CPU
- on charge le model sur le hardware choisi
- apprentissage : à chaque epoch on lance le timer et les données sont présentées au réseau.
Un Chunk (séquence de 256 IQ) est présenté et passe dans le réseau, puis une autre jusqu'a atteindre batchsize. Lorsque le nombre de Chunk présenté atteint batchsize le réseau est mis à jour par backpropagation et on passe au batch suivant. Une fois que tout les batch ont été parcouru on a atteint une epoch, on va tester l'accuracy du reseau en Test et en Train et afficher les résultats.
- Après chaque epoque le Timer est arrété et le score F1 est calculé par la fonction F1Score
return nn,trainLoss,trainAcc,testLoss,testAcc,args



function F1Score(loader,model,device=cpu)
- calcul le F1 score global à partir des estimations de classe et les classes vraies.
return F1
7 changes: 4 additions & 3 deletions src/RiFyFi_VDG/src/RiFyFi_VDG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ using Statistics
using CSV
using DelimitedFiles
using DataFrames
using Infiltrator
include("../../Augmentation/src/Augmentation.jl")
using .Augmentation
# ----------------------------------------------------
Expand Down Expand Up @@ -60,8 +61,8 @@ function setSynthetiquecsv(Param_Data)
(bigMatTrain,bigLabel_Train,bigMatTest,bigLabel_Test,X) = create_virtual_Database(Param_Data)
bigLabels_Train = create_bigMat_Labels_Tx(bigLabel_Train)
bigLabels_Test = create_bigMat_Labels_Tx(bigLabel_Test)

if Param_Data.Augmentation_Value.augmentationType == "sans"
@infiltrate
if Param_Data.Augmentation_Value.augmentationType == "No_channel"
savepath = "./CSV_Files/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)/$(Param_Data.E)_$(Param_Data.S)/$(Param_Data.E)_$(Param_Data.S)_$(Param_Data.C)_$(Param_Data.RFF)_$(Param_Data.nbSignals)_$(Param_Data.nameModel)"
else
savepath = "./CSV_Files/$(Param_Data.Augmentation_Value.augmentationType)_$(Param_Data.nbTx)_$(Param_Data.Chunksize)/$(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)"
Expand Down Expand Up @@ -266,7 +267,7 @@ function loadCSV_Synthetic(Param_Data)
nbChunks=Int(nbRadioTx*nbSignaux)
nbTrain = Int(round(pourcentTrain*nbChunks))
nbTest = nbChunks - nbTrain
if augmentationType == "sans"
if augmentationType == "No_channel"
savepath = "./CSV_Files/$(augmentationType)_$(nbRadioTx)_$(ChunkSize)/$(E)_$(S)/$(E)_$(S)_$(C)_$(RFF)_$(nbSignaux)_$(name)"
else
channel = Param_Data.Augmentation_Value.Channel
Expand Down
99 changes: 0 additions & 99 deletions src/RiFyFi_VDG/src/Struct_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,102 +129,3 @@ function Data_Synth_construct(; kwargs...)
end
return Data_Synth(name,nameModel,nbTx,nbSignals,Chunksize,features,S,E,C,RFF,Normalisation,pourcentTrain,configuration,seed_data,seed_model,seed_dataTest,seed_modelTest,Augmentation_Value)
end

#=
Base.@kwdef mutable struct Data_WiSig
File_name::String = "../My_WiSig_ManySig/pkl_wifi_ManySig/ManySig.pkl"
name::String = "WiSig"
nbTx::Int = 6
nbSignals::Int = 1000
Chunksize::Int = 256
features::String= "IQsamples"
txs = 1:6
rxs = 1
days = 1
equalized= 1
Normalisation::Bool = true
pourcentTrain::Float64 =0.9
Augmentation_Value::Data_Augmented = Data_Augmented()
end
function Data_WiSig(; kwargs...)
if haskey(kwargs, :File_name)
File_name = kwargs[:File_name]
else
File_name="../My_WiSig_ManySig/pkl_wifi_ManySig/ManySig.pkl"
end
if haskey(kwargs, :name)
name = kwargs[:name]
else
name="WiSig"
end
if haskey(kwargs, :nbTx)
nbTx = kwargs[:nbTx]
else
nbTx = 6
end
if haskey(kwargs, :nbSignals)
nbSignals = kwargs[:nbSignals]
else
nbSignals = 1000
end
if haskey(kwargs, :Chunksize)
Chunksize = kwargs[:Chunksize]
else
Chunksize = 256
end
if haskey(kwargs, :features)
features = kwargs[:features]
else
features = "IQsamples"
end
if haskey(kwargs, :txs)
txs = kwargs[:txs]
else
txs = 1:6
end
if haskey(kwargs, :rxs)
rxs = kwargs[:rxs]
else
rxs = 1
end
if haskey(kwargs, :days)
days = kwargs[:days]
else
days = 1
end
if haskey(kwargs, :equalized)
equalized = kwargs[:equalized]
else
equalized =1
end
if haskey(kwargs, :Normalisation)
Normalisation = kwargs[:Normalisation]
else
Normalisation = true
end
if haskey(kwargs, :pourcentTrain)
pourcentTrain = kwargs[:pourcentTrain]
else
pourcentTrain = 0.9
end
if haskey(kwargs, :Augmentation_Value)
Augmentation_Value = kwargs[:Augmentation_Value]
else
Augmentation_Value = Data_Augmented()
end
return Data_WiSig(File_name,name, nbTx, nbSignals, Chunksize,features, txs,rxs,days,equalized,Normalisation,pourcentTrain,Augmentation_Value)
end
=#
Loading

0 comments on commit 20fd42c

Please sign in to comment.