-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotWindowFIRResponse.m
150 lines (129 loc) · 4.3 KB
/
plotWindowFIRResponse.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
% FILE: plotWindowFIRResponse.m
%
% FUNCTION: plotWindowFIRResponse
%
% CALL: [] = plotWindowFIRResponse(w, titles, order, wc, Ts, wn_param)
%
% Plots the frequency response of the specified windows, with cutoff
% frequency wc, samplit period Ts and using the parameters in wn_param for
% the windows.
% SUPPORTS ONLY LOW-PASS FILTER AT THE MOMENT !
%
% INPUTS:
% w - window names
% titles - titles for the plots
% order - filter order
% wc - cutoff frequency
% Ts - sampling period
% window - a vector with the window elements, the vector has size
% order + 1
%
%
% Author: Leonard-Gabriel Necula
% Created: December 24 2020
% Updated: January 18 2021
function [] = plotWindowFIRResponse(w, titles, order, wc, Ts, wn_param)
if nargin < 1
disp('No window names detected. Setting default data windows.')
[w, ~] = getWindowName();
elseif isempty(w)
disp('Empty window names. Setting default data windows.')
[w, ~] = getWindowName();
end
if nargin < 2
disp('Titles missing. Setting titles to default.');
[~, titles] = getWindowName();
elseif isempty(titles)
disp('Titles found empty. Setting titles to default.');
[~, titles] = getWindowName();
end
if nargin < 3
disp('Order missing. Set default order to 16');
order = 16;
elseif isempty(order)
disp('Order empty. Set default order to 16');
order = 16;
end
if nargin < 4
wc = 0.4 * pi;
disp('Cutoff frequency missing. Set wc to 0.4pi.');
elseif isempty(wc)
wc = 0.4 * pi;
disp('Cutoff frequency left empty. Set wc to 0.4pi.');
end
if nargin < 5
disp('Sampling period missing. Set Ts = 1.');
Ts = 1;
elseif isempty(Ts)
disp('Sampling period empty. Set Ts = 1.');
Ts = 1;
end
if nargin < 6
wn_param = setDefaultParamsForAllWindows(w);
elseif isempty(wn_param)
wn_param = setDefaultParamsForAllWindows(w);
end
% Check if wn_param was set right
checkIndex = 0;
for i = 1:numel(w)
if checkType(w{i}, [4, 7, 8, 9])
checkIndex = checkIndex + 1;
end
end
if numel(wn_param) ~= checkIndex
disp('Too many or too little parameters given. Setting default.');
wn_param = setDefaultParamsForAllWindows(w);
end
lineNumber = factor(numel(w));
colNumber = lineNumber(1);
lineNumber = lineNumber(2:end);
lineNumber = prod(lineNumber);
% GAIN
wn_index = 1;
figure;
for i = 1 : length(titles)
subplot(lineNumber, colNumber, i);
if checkType(w{i}, [4, 7, 8, 9])
Wn = getWindow(w{i}, order + 1, wn_param(wn_index));
wn_index = wn_index + 1;
else
Wn = getWindow(w{i}, order + 1);
end
[b, a] = FIR(order, wc, Ts, Wn, 'low');
[H, omega] = freqz(b, a, 512);
plotGain(H, omega, strcat(titles{i}, [' amplitude order - ',....
num2str(order)]));
end
% DB GAIN
wn_index = 1;
figure;
for i = 1 : length(titles)
subplot(lineNumber, colNumber, i);
if checkType(w{i}, [4, 7, 8, 9])
Wn = getWindow(w{i}, order + 1, wn_param(wn_index));
wn_index = wn_index + 1;
else
Wn = getWindow(w{i}, order + 1);
end
[b, a] = FIR(order, wc, Ts, Wn, 'low');
[H, omega] = freqz(b, a, 512);
plotGainDB(H, omega, strcat(titles{i}, [' amplitude in dB order - ',....
num2str(order)] ));
end
% Phase
wn_index = 1;
figure;
for i = 1 : length(titles)
subplot(lineNumber, colNumber, i);
if checkType(w{i}, [4, 7, 8, 9])
Wn = getWindow(w{i}, order + 1, wn_param(wn_index));
wn_index = wn_index + 1;
else
Wn = getWindow(w{i}, order + 1);
end
[b, a] = FIR(order, wc, Ts, Wn, 'low');
[H, omega] = freqz(b, a, 512);
plotPhase(H, omega, strcat(titles{i}, [' phase order - ',....
num2str(order)]));
end
end