-
Notifications
You must be signed in to change notification settings - Fork 0
/
virus_sig.m
82 lines (67 loc) · 1.94 KB
/
virus_sig.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
% Simulation for CyberAttk. Computer virus simulation signal modulation
close all;
clear;
%%% adjuste according to the actual situation %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fs=1000; % sampling frequecy
fc=120e9; % center freq: 120 GHz
bitRate=1e6; % data rate: 1 Mbps
numBits=200; % number of binary digits
zeropad=16; % zero-padding
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Step 1: Generate a random stream of computer code data to simulate a virus
% code data generation
% like Hexadecimal to Binary...
data_binary=randi([0 1],1,numBits); % generate random binary data
bitDuration=1/bitRate; % duration of each bit of data
%disp(code_data);
%% Step 2: Generate a carrier signal
% time vector
t=linspace(0,bitDuration*length(data_binary),length(data_binary)*fs);
% carrier signal
carrierSig=cos(2*pi*fc*t);
% FFT
FFTc=fft(carrierSig,length(carrierSig)*zeropad);
figure;
plot(abs(FFTc));
title('FFT of carrier signal')
%% Step 3: FSK modulation
modulatedSig=[];
for i = 1:length(data_binary)
if data_binary(i) == 0
modulatedSig=[modulatedSig cos(2*pi*(fc-bitRate/2)*t((i-1)*fs+1:i*fs))];
else
modulatedSig=[modulatedSig cos(2*pi*(fc+bitRate/2)*t((i-1)*fs+1:i*fs))];
end
end
% FFT
FFTm=fft(modulatedSig,length(modulatedSig)*zeropad);
figure;
plot(abs(FFTm));
title('FFT of modulated signal')
% emitted signal generation
emittedSig=modulatedSig+carrierSig;
% FFT
FFTe=fft(emittedSig,length(emittedSig)*zeropad);
figure;
plot(abs(FFTe));
title('FFT of emitted signal')
%% Print figures...
figure;
plot(t,carrierSig);
xlabel('Time');
ylabel('Amplitude');
title('Carrier Signal');
figure;
plot(t,modulatedSig);
xlabel('Time');
ylabel('Amplitude');
title('Modulated Signal');
figure;
plot(t,emittedSig);
xlabel('Time');
ylabel('Amplitude');
title('Emitted Signal');
figure;
spectrogram(emittedSig,hann(256),250,1024,fs,'yaxis');
title('Spectrum');