matthiasm@0
|
1 function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyHighpassFilter(f_audio, samplingFreq, timepositions_beforeDegr, parameter)
|
matthiasm@0
|
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
3 % Name: degradation_applyHighpassFilter
|
matthiasm@0
|
4 % Date: 2013-04
|
matthiasm@0
|
5 % Programmer: Matthias Mauch
|
matthiasm@0
|
6 %
|
matthiasm@0
|
7 % Description:
|
matthiasm@0
|
8 % - applies a highpass filter to the audio
|
matthiasm@0
|
9 %
|
matthiasm@0
|
10 % Input:
|
matthiasm@0
|
11 % f_audio - audio signal \in [-1,1]^{NxC} with C being the number of
|
matthiasm@0
|
12 % channels
|
matthiasm@0
|
13 % timepositions_beforeDegr - some degradations delay the input signal. If
|
matthiasm@0
|
14 % some points in time are given via this
|
matthiasm@0
|
15 % parameter, timepositions_afterDegr will
|
matthiasm@0
|
16 % return the corresponding positions in the
|
matthiasm@0
|
17 % output. Set to [] if unavailable. Set f_audio
|
matthiasm@0
|
18 % and samplingFreq to [] to compute only
|
matthiasm@0
|
19 % timepositions_afterDegr.
|
matthiasm@0
|
20 %
|
matthiasm@0
|
21 % Input (optional): parameter
|
matthiasm@0
|
22 % .stopFrequency = 200 - stop band edge frequency in Hz
|
matthiasm@0
|
23 % .passFrequency = - pass band edge frequency in Hz,
|
matthiasm@0
|
24 % default is 2 x [stop band edge frequency]
|
matthiasm@0
|
25 %
|
matthiasm@0
|
26 % Output:
|
matthiasm@0
|
27 % f_audio_out - audio output signal
|
matthiasm@0
|
28 %
|
matthiasm@0
|
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
30
|
matthiasm@0
|
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
32 % Audio Degradation Toolbox
|
matthiasm@0
|
33 %
|
matthiasm@0
|
34 % Centre for Digital Music, Queen Mary University of London.
|
matthiasm@0
|
35 % This file copyright 2013 Sebastian Ewert, Matthias Mauch and QMUL.
|
matthiasm@0
|
36 %
|
matthiasm@0
|
37 % This program is free software; you can redistribute it and/or
|
matthiasm@0
|
38 % modify it under the terms of the GNU General Public License as
|
matthiasm@0
|
39 % published by the Free Software Foundation; either version 2 of the
|
matthiasm@0
|
40 % License, or (at your option) any later version. See the file
|
matthiasm@0
|
41 % COPYING included with this distribution for more information.
|
matthiasm@0
|
42 %
|
matthiasm@0
|
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
44
|
matthiasm@0
|
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
46 % Check parameters
|
matthiasm@0
|
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
48 if nargin<4
|
matthiasm@0
|
49 parameter=[];
|
matthiasm@0
|
50 end
|
matthiasm@0
|
51 if nargin<3
|
matthiasm@0
|
52 timepositions_beforeDegr=[];
|
matthiasm@0
|
53 end
|
matthiasm@0
|
54 if nargin<2
|
matthiasm@0
|
55 error('Please specify input data');
|
matthiasm@0
|
56 end
|
matthiasm@0
|
57
|
matthiasm@0
|
58 if isfield(parameter,'stopFrequency')==0
|
matthiasm@0
|
59 parameter.stopFrequency = 200;
|
matthiasm@0
|
60 end
|
matthiasm@0
|
61 if isfield(parameter,'passFrequency')==0
|
matthiasm@0
|
62 parameter.passFrequency = 2 * parameter.stopFrequency;
|
matthiasm@0
|
63 end
|
matthiasm@0
|
64
|
matthiasm@0
|
65 if parameter.stopFrequency > parameter.passFrequency
|
matthiasm@0
|
66 error('Please choose a pass frequency greater than the stop frequency.');
|
matthiasm@0
|
67 end
|
matthiasm@0
|
68
|
matthiasm@0
|
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
70 % Main program
|
matthiasm@0
|
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
72
|
matthiasm@0
|
73 f_audio_out = [];
|
matthiasm@0
|
74 if ~isempty(f_audio)
|
matthiasm@0
|
75
|
matthiasm@0
|
76 omega_stop = parameter.stopFrequency / samplingFreq * 2 * pi; % stopband omega
|
matthiasm@0
|
77 omega_pass = parameter.passFrequency / samplingFreq * 2 * pi; % passband omega
|
matthiasm@0
|
78 transition_width = abs(omega_stop-omega_pass);
|
matthiasm@0
|
79
|
matthiasm@0
|
80 lobe_width = 3.32;
|
matthiasm@0
|
81 filter_order = ceil(lobe_width*pi/transition_width); % filter order via transition bandwidth (see lecture)
|
matthiasm@0
|
82
|
matthiasm@0
|
83
|
matthiasm@0
|
84 filter_length = 2*filter_order + 1;
|
matthiasm@0
|
85
|
matthiasm@0
|
86 n = 0:(filter_length-1);
|
matthiasm@0
|
87 omega_cutoff = (omega_stop+omega_pass)/2; % cutoff frequency is mean of pass and stopband edges
|
matthiasm@0
|
88 alpha = (filter_length-1)/2;
|
matthiasm@0
|
89 m = n - alpha; % symmetricised indices
|
matthiasm@0
|
90
|
matthiasm@0
|
91 hd = -omega_cutoff/pi * sinc(omega_cutoff/pi*m);
|
matthiasm@0
|
92 hd(alpha+1) = hd(alpha+1) + 1;
|
matthiasm@0
|
93
|
matthiasm@0
|
94 window = hamming(filter_length)';
|
matthiasm@0
|
95 h = hd .* window;
|
matthiasm@0
|
96
|
matthiasm@0
|
97 f_audio_out = fftfilt(h, [f_audio; zeros([filter_order, size(f_audio,2)])]);
|
matthiasm@0
|
98 f_audio_out = f_audio_out((filter_order + 1):end, :);
|
matthiasm@0
|
99
|
matthiasm@0
|
100
|
matthiasm@0
|
101 f_audio_out(f_audio_out < -1) = -1;
|
matthiasm@0
|
102 f_audio_out(f_audio_out > 1) = 1;
|
matthiasm@0
|
103 f_audio_out = f_audio_out * 0.999;
|
matthiasm@0
|
104
|
matthiasm@0
|
105 end
|
matthiasm@0
|
106
|
matthiasm@0
|
107 % This degradation has no delay.
|
matthiasm@0
|
108 timepositions_afterDegr = timepositions_beforeDegr;
|
matthiasm@0
|
109
|
matthiasm@0
|
110 end
|