-
Notifications
You must be signed in to change notification settings - Fork 49
/
ArbitraryOctaveFilt.m
52 lines (47 loc) · 1.3 KB
/
ArbitraryOctaveFilt.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
function y = ArbitraryOctaveFilt(x, SPECT, FREQS, N, fs, octBandwidth)
% Filters a signal with any arbitrary spectrum smoothed with any fractional octave band average
%
% Syntax: Y = ARBITRARYOCTAVEFILT(X, SPECT, FREQS, N, FS, OCTBANDWIDTH)
%
% Inputs:
% x - Input signal to filter as a vector
% SPECT - The spectrum to shape the input signal to
% FREQS - The frequencies of each SPECT element
% N - The length of the filter to usee
% fs - Description
% octBandwidth - Description
%
% Outputs:
% y - Description
%
% Example:
% fs = 16000;
% T = 10;
% N = 1000;
% f = linspace(0,fs/2,N);
% s = 1./f;
% x = wgn(T*fs,1,0);
% y = ArbitraryOctaveFilt(x,s,f,N,fs,1/3);
% pwelch([x y]);
%
% See also: fir2, filter
% Author: Jacob Donley
% University of Wollongong
% Email: [email protected]
% Copyright: Jacob Donley 2017
% Date: 06 June 2016
% Revision: 0.1
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if nargin < 6
octBandwidth = 1/6;
end
% Find nth-octave averages
[MAG,f]=Tools.octaveBandMean(SPECT,FREQS,octBandwidth);
% Force even length filter
if isempty(N), if mod(length(SPECT),2), N=length(SPECT)-1; else N=length(SPECT); end; end
% Design arbitrary magnitude (linear-phase) filter
b = fir2(N,f/(fs/2),MAG);
% Apply filter
y = filter(b,1,x);
end