-
Notifications
You must be signed in to change notification settings - Fork 0
/
freq_resp_cal.m
51 lines (41 loc) · 1.19 KB
/
freq_resp_cal.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
function [mag,Freq]=freq_resp_cal(y,u,Fs)
% This function computes the magnitude and phase of the frequency response between u (input)
% and y (output) using the spectral analysis.
%
% Xu Chen xchen@engr.uconn.edu
% University of Connecticut
FRF = [];
%Fs = 800;
Ts = 1/Fs;
fmin_visu = 1;
fmax_visu = round(Fs/2);
if 1
L = length(u);
% if b_autoNFFT
NFFT = 2^nextpow2(L);
% end
else
Nfft = 2048/2;
end
window = hanning(Nfft);
noverlap = 0.75*Nfft;
%[Txy,Freq] = tfe(u,y,Nfft,Fs,window,noverlap) ;
[Txy,Freq] = tfestimate(u,y,window,noverlap,Nfft,Fs) ;
ind = find(Freq>fmin_visu & Freq<fmax_visu);
figure;
plot(Freq(ind),20*log10(abs(Txy(ind))));grid
title('Magnitude of the frequency response of the secondary path obtained by spectral analysis')
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
%
% figure;
% semilogx(Freq(ind),20*log10(abs(Txy(ind))));grid
% title('Magnitude of the frequency response of the secondary path obtained by spectral analysis')
% xlabel('Frequency (Hz)');
% ylabel('Magnitude (dB)');
% figure;
% plot(Freq(ind),180/pi*(angle(Txy(ind))));grid
% xlabel('Fréquency (Hz)');
% ylabel('Phase (°)');
mag=20*log10(abs(Txy));
%pha=180/pi*(angle(Txy));