-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathidprbs.m
More file actions
82 lines (74 loc) · 2.47 KB
/
Copy pathidprbs.m
File metadata and controls
82 lines (74 loc) · 2.47 KB
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
function [s,t] = idprbs(N,ampl,ts,F,Fstop,t0,p)
%IDPRBS Generation of a Pseudo-Random Binary Signal (PRBS)
% [S,T] = IDPRBS(N,AMPL,Ts,F,Fstop,T0,P) generatos a Pseudo-Random Binary
% Signal (PRBS) with the following properties:
%
% N : signal length [s]
% AMPL (optional) : amplitude (default: 1)
% Ts (optional) : sampling time [s] (default: 1)
% F (optional) : cutoff frequency [Hz] (default: 0.5/pars.ts)
% Fstop (optional) : PRBS will be band-stop filtered around this frequency
% (default: inf)
% T0 (optional) : starting time [s] (default: 0)
% P (optional) : number of channels (default: 1)
%
% See also IDINPUTS, IDMULTISINE.
% check number if input arguments
if nargin < 1
error('ID requires at least one input argument.')
end
if nargin < 7 || isempty(p)
p = 1;
end
if nargin < 6 || isempty(t0)
t0 = 0;
end
if nargin < 5 || isempty(Fstop)
Fstop = inf;
end
if nargin < 3 || isempty(ts)
ts = 1;
end
if nargin < 4 || isempty(F)
F = 0.5/ts;
end
if nargin < 2 || isempty(ampl)
ampl = 1;
end
if F==0
warning('ID:cutoffzero','Selected cutoff frequency is zero, returning zero PRBS signal...')
s = zeros(1,ceil(N/ts));
t = t0 + ts * (0:1:length(s)-1)';
return
end;
Fnyq = 0.5/ts; % Nyquist frequency
if F > Fnyq
warning('ID:bandbeyondnyqst','Specified bandwidth [0, %s] Hz is beyond the Nyquist frequency %s Hz',num2str(F),num2str(Fnyq))
F = Fnyq;
warning('ID:bandbeyondnyqst','>>> BANDWIDTH MODIFIED TO [0, %s] Hz <<<',num2str(F))
end;
% Making L=2^N-1
N = ceil(log2(N/ts + 1));
L=2^N-1;
% Bandwidth as fraction of Nyquist frequency
FbyFnyq = F/Fnyq;
Bnd = [0, FbyFnyq];
s = idinput([L, p],'prbs',Bnd,ampl*[-1,1]);
% Low-pass filtering PRBS signal
if FbyFnyq < 1
Fircoefs = fir1(2000, FbyFnyq, kaiser(2000+1,300));
%Fircoefs = fir1(100,FbyFnyq,kaiser(100+1,5));
s = filter(Fircoefs,1,s);
end
% band-stop filtering PRBS signal
if Fstop < F
Bnd = [0.7, 1.3] * Fstop / Fnyq;
Bnd(2) = min(1, Bnd(2)); % make sure Fnyq > Bnd*Fnyq
[B,A] = ellip(4,1,20,Bnd,'stop');
s = filter(B,A,s);
else
warning('ID:bandlargercutoff','The frequency to be filtered out, %s Hz, is larger than the cutoff frequency %s Hz',num2str(Fstop), num2str(F))
warning('ID:bandlargercutoff','>>> Skipping band stop filtering around %s Hz <<<',num2str(Fstop))
end
% time stamps for s
t = t0 + ts * (0:1:length(s)-1)';