-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIR_spectrum.m
115 lines (69 loc) · 2.11 KB
/
IR_spectrum.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
clear; close all;
% General Parameters
f_au_t = 1378999.4; %freq of an oscillation of perdiod 1 au in cm^-1
dt = 100; %simulation time-step
fsf = f_au_t/dt; %frequency scaling factor
fmax = 3500; %upper bound to plot
step = [0:2:14]; %initial : step : final
%% Raw plotting
%figure creation
fig = figure;
ax = axes(fig);
xlim([0,fmax])
set(ax, 'YTick', zeros(1,0))
title("IR spectrum for H_2O molecules", 'FontSize',18)
set(ax, 'FontSize',16)
hold on
for i=step
file_loc = sprintf("/Volumes/THEO/MAGISTRALE/Materie/Atomistic Simulation Methods/Exam/dipole/dip%04i.dat",i);
%Find the options of the file
opts = detectImportOptions(file_loc);
%modify the Variabe Names
opts.VariableNames = {'ex','ey','ez'};
%read the data
d = readtable(file_loc,opts);
% computing the power spectrum of each column of d
[spx,f] = pspectrum(d.ex,fsf);
[spy,f] = pspectrum(d.ey,fsf);
[spz,f] = pspectrum(d.ez,fsf);
% compute the IR spectrum
s = (f.^2) .* (spx + spy + spz);
plot(f,s)
end
hold off
%% Filtered plot
%figure creation
fig = figure;
ax = axes(fig);
xlim([0,fmax])
set(ax, 'YTick', zeros(1,0))
title("IR spectrum for H_2O molecules", 'FontSize',18)
set(ax, 'FontSize',16)
xlabel("frequency [cm^{-1}]")
ylabel("IR absorpion [a.u]")
box on;
hold on
h = create_filter(100);
for i=step
file_loc = sprintf("/Volumes/THEO/MAGISTRALE/Materie/Atomistic Simulation Methods/Exam/dipole/dip%04i.dat",i);
%Find the options of the file
opts = detectImportOptions(file_loc);
%modify the Variabe Names
opts.VariableNames = {'ex','ey','ez'};
%read the data
d = readtable(file_loc,opts);
% computing the power spectrum of each column of d
[spx,f] = pspectrum(d.ex,fsf);
[spy,f] = pspectrum(d.ey,fsf);
[spz,f] = pspectrum(d.ez,fsf);
% compute the IR spectrum
s = (f.^2) .* (spx + spy + spz);
s_filtered = conv(h,s,'same');
plot(f,s_filtered,'LineWidth',1)
xlim([0,fmax])
end
hold off
function h = create_filter(alpha)
x = linspace(-5,5,4096);
h = exp(-alpha*x.^2);
end