-
Notifications
You must be signed in to change notification settings - Fork 0
/
Homework_3.m
209 lines (202 loc) · 8 KB
/
Homework_3.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
%% MECHANICAL VIBRATIONS (2021/1) - HOMEWORK 3
% Docente: Michael John Brennan
% Discente: Estevao Fuzaro de Almeida
% Data: 25/03/2021
% INICIALIZACAO
clc; clear all; close all; format long; %#ok<*CLALL>
set(groot,'defaultAxesTickLabelInterpreter','latex');
set(groot,'defaultLegendInterpreter','latex');
set(groot,'defaultTextInterpreter','latex');
txtsize = 26;
lgndsize = 20;
%% VARIAVEIS
m = 1; % Massa [kg]
k = 1e4; % Rigidez [N/m]
z = [0.001 0.01 0.1]; % Zeta [adimensional]
dt = 0.001; % Incremento de Tempo [s]
df = 0.001; % Incremento de Frequencia [Hz]
fs = 1/dt; % Freq. de Amostragem [Hz]
t = 0:dt:200; % Vetor de Tempo [s]
f = 0:df:(fs/2); % Frequencia [Hz]
w = 2*pi*f; % Freq. Angular [rad/s]
%% PARAMETROS DO SISTEMA
wn = sqrt(k/m); % Freq. Natural [rad/s]
fn = wn/(2*pi); % Freq. Natural [Hz]
wd = wn*sqrt(1-z.^2); % Freq. Nat. Amortecida [rad/s]
c = 2*z*sqrt(k*m); % Amortecimento [N.s/m]
%% IRF [h(t)]
ht = []; Hjw = []; env = []; % Pré-alocando os vetores
for st=1:3
ht(st,:) = 1/(m*wd(st))*exp(-z(st)*wn*t).*sin(wd(st)*t); %#ok<*SAGROW>
Hjw(st,:) = 1./(k-w.^2*m+1i*w*c(st));
env(st,:) = 1/(m*wd(st))*exp(-z(st)*wn*t);
end
%% TRANSFORMADA DE FOURIER DE h(t)
Ts = [160 40 10]; % T Amostragem para cada zeta [s]
DiscFreq = 1./Ts; % Freq. Discretizada [Hz]
% ABS(X/F) PELA FREQUENCIA
figure
set(gcf,'Units','Normalized','OuterPosition',[0 0 1 0.6])
for st=1:3
subplot(1,3,st)
if st==1
Fs = 0:DiscFreq(st):fs;
loglog(f,abs(Hjw(st,:)),'m','linewidth', 2), hold on
axis([1e-1 0.5e3 1e-7 1e-1])
elseif st==2
Fs = 0:DiscFreq(st):fs;
loglog(f,abs(Hjw(st,:)),'k','linewidth', 2), hold on
axis([1e-1 0.5e3 1e-7 1e-1])
else
Fs = 0:DiscFreq(st):fs;
loglog(f,abs(Hjw(st,:)),'b','linewidth', 2), hold on
axis([1e-1 0.5e3 1e-7 1e-1])
end
HjwFT = fft(ht(st,1:length(Fs)))*dt;
loglog(Fs(1:fs/(2*DiscFreq(st))),abs(HjwFT(1:fs/(2*DiscFreq(st)))),'r--','linewidth', 2.5), hold on
xlabel('$f$ [Hz]')
ylabel('Receptance [m/N]')
legend({'$\left|H(j\omega)\right|$','$\left|FT[h(t)]\right|$'},'Location','southwest','fontsize',lgndsize)
title(['$\zeta = ', num2str(z(st)), ' $'],'FontWeight','normal')
grid on, grid minor
set(gca,'fontsize',txtsize,'Xtick',[1e-1 1e0 1e1 1e2 1e3],'Ytick',[1e-7 1e-6 1e-5 1e-4 1e-3 1e-2 1e-1],'XColor','k','YColor','k','ZColor','k','GridColor','k')
end
% ANGULO(X/F) PELA FREQUENCIA
figure
set(gcf,'Units','Normalized','OuterPosition',[0 0 1 0.6])
for st=1:3
subplot(1,3,st)
if st==1
Fs = 0:DiscFreq(st):fs;
plot(f,rad2deg(angle(Hjw(st,:))),'m','linewidth', 2), hold on
elseif st==2
Fs = 0:DiscFreq(st):fs;
plot(f,rad2deg(angle(Hjw(st,:))),'k','linewidth', 2), hold on
else
Fs = 0:DiscFreq(st):fs;
plot(f,rad2deg(angle(Hjw(st,:))),'b','linewidth', 2), hold on
end
HjwFT = fft(ht(st,1:length(Fs)))*dt;
plot(Fs(1:fs/(2*DiscFreq(st))),rad2deg(angle(HjwFT(1:fs/(2*DiscFreq(st))))),'r--','linewidth', 2.5), hold on
xlabel('$f$ [Hz]')
legend({'$\angle H(j\omega)$','$\angle FT[h(t)]$'},'Location','northeast','fontsize',lgndsize)
ylabel('Receptance $\phi$ [$^{\circ}$]')
title(['$\zeta = ', num2str(z(st)), ' $'],'FontWeight','normal')
grid on, grid minor
xlim([0 80])
set(gca,'fontsize',txtsize,'Ytick',[-180 -135 -90 -45 0],'XColor','k','YColor','k','ZColor','k','GridColor','k')
end
%% DOUBLE-SIDED SPECTRUM [DSS] PELA FREQUENCIA
figure
set(gcf,'Units','Normalized','OuterPosition',[0 0 1 0.6])
for st=1:3
DSfreq = 0:df:fs;
DSSHjw = [Hjw(st,:) fliplr(conj(Hjw(st,:)))];
DSSHjw = DSSHjw(1:length(DSfreq));
subplot(1,3,st)
if st==1
Fs = 0:DiscFreq(st):fs;
semilogy(DSfreq,abs(DSSHjw),'m','linewidth', 2), hold on
axis([0 fs 1e-7 1e-1])
elseif st==2
Fs = 0:DiscFreq(st):fs;
semilogy(DSfreq,abs(DSSHjw),'k','linewidth', 2), hold on
axis([0 fs 1e-7 1e-1])
else
Fs = 0:DiscFreq(st):fs;
semilogy(DSfreq,abs(DSSHjw),'b','linewidth', 2), hold on
axis([0 fs 1e-7 1e-1])
end
HjwFT = fft(ht(st,1:length(Fs)))*dt;
semilogy(Fs,abs(HjwFT),'r--','linewidth', 2.5), hold on
xlabel('$f$ [Hz]')
ylabel('Receptance [m/N]')
legend({'DSS of H(j$\omega$)','DSS of FT[$h(t)$]'},'Location','northeast','fontsize',lgndsize)
title(['$\zeta = ', num2str(z(st)), ' $'],'FontWeight','normal')
grid on, grid minor
set(gca,'fontsize',txtsize,'Ytick',[1e-7 1e-6 1e-5 1e-4 1e-3 1e-2 1e-1],'XColor','k','YColor','k','ZColor','k','GridColor','k')
end
% ANGULO DO DSS PELA FREQUENCIA
figure
set(gcf,'Units','Normalized','OuterPosition',[0 0 1 0.6])
for st=1:3
DSfreq = 0:df:fs;
DSSHjw = [Hjw(st,:) fliplr(conj(Hjw(st,:)))];
DSSHjw = DSSHjw(1:length(DSfreq));
subplot(1,3,st)
if st==1
Fs = 0:DiscFreq(st):fs;
plot(DSfreq,rad2deg(unwrap(angle(DSSHjw))),'m','linewidth', 2), hold on
elseif st==2
Fs = 0:DiscFreq(st):fs;
plot(DSfreq,rad2deg(unwrap(angle(DSSHjw))),'k','linewidth', 2), hold on
else
Fs = 0:DiscFreq(st):fs;
plot(DSfreq,rad2deg(unwrap(angle(DSSHjw))),'b','linewidth', 2), hold on
end
HjwFT = fft(ht(st,1:length(Fs)))*dt;
plot(Fs,rad2deg(unwrap(angle(HjwFT))),'r--','linewidth', 2.5), hold on
xlabel('$f$ [Hz]')
ylabel('Receptance $\phi$ [$^{\circ}$]')
legend({'DSS of H(j$\omega$)','DSS of FT[$h(t]$)'},'Location','northeast','fontsize',lgndsize)
title(['$\zeta = ', num2str(z(st)), ' $'],'FontWeight','normal')
grid on, grid minor
ylim([-360 0])
set(gca,'fontsize',txtsize,'Ytick',[-360 -270 -180 -90 0],'XColor','k','YColor','k','ZColor','k','GridColor','k')
end
%% PLOT DE h(t) E DA IFT[H(jw)] PELO TEMPO
figure
set(gcf,'Units','Normalized','OuterPosition',[0 0 1 0.6])
DStime = 0:1/fs:1/df;
for st=1:3
DSSHjw = [Hjw(st,:) fliplr(conj(Hjw(st,:)))];
DSSHjw = DSSHjw(1:length(DStime));
htFT = ifft(DSSHjw)*fs;
subplot(1,3,st)
if st==1
plot(t,ht(st,:),'m','linewidth', 2), hold on
plot(DStime,htFT,'--r','linewidth', 2.2), hold on
axis([0 60 -1e-2 1e-2])
elseif st == 2
plot(t,ht(st,:),'k','linewidth', 2), hold on
plot(DStime,htFT,'--r','linewidth', 2.2), hold on
axis([0 6 -1e-2 1e-2])
else
plot(t,ht(st,:),'b','linewidth', 2), hold on
plot(DStime,htFT,'--r','linewidth', 2.2), hold on
axis([0 0.6 -1e-2 1e-2])
end
xlabel('$t$ [s]')
ylabel('$h(t)$ [m/N.s]')
legend({'$h(t)$','IFT[H(j$\omega$)]'},'Location','southeast','fontsize',lgndsize)
title(['$\zeta = ', num2str(z(st)), ' $'],'FontWeight','normal')
set(gca,'fontsize',txtsize,'XColor','k','YColor','k','ZColor','k','GridColor','k')
grid on; grid minor;
end
figure
set(gcf,'Units','Normalized','OuterPosition',[0 0 1 0.6])
for st=1:3
DSSHjw = [Hjw(st,:) fliplr(conj(Hjw(st,:)))];
DSSHjw = DSSHjw(1:length(DStime));
htFT = ifft(DSSHjw)*fs;
subplot(1,3,st)
if st==1
plot(t,ht(st,:),'m','linewidth', 3), hold on
plot(DStime,htFT,'--r','linewidth', 3), hold on
axis([0 0.2 -1e-2 1e-2])
elseif st == 2
plot(t,ht(st,:),'k','linewidth', 3), hold on
plot(DStime,htFT,'--r','linewidth', 3), hold on
axis([0 0.2 -1e-2 1e-2])
else
plot(t,ht(st,:),'b','linewidth', 3), hold on
plot(DStime,htFT,'--r','linewidth', 3), hold on
axis([0 0.2 -1e-2 1e-2])
end
xlabel('$t$ [s]')
ylabel('$h(t)$ [m/N.s]')
legend({'$h(t)$','IFT[H(j$\omega$)]'},'Location','southeast','fontsize',lgndsize)
title(['$\zeta = ', num2str(z(st)), ' $'],'FontWeight','normal')
set(gca,'fontsize',txtsize,'XColor','k','YColor','k','ZColor','k','GridColor','k')
grid on; grid minor;
end