~ubuntu-branches/ubuntu/utopic/soundscaperenderer/utopic-proposed

« back to all changes in this revision

Viewing changes to data/matlab_scripts/make_wfs_prefilter.m

  • Committer: Package Import Robot
  • Author(s): IOhannes m zmölnig (Debian/GNU)
  • Date: 2014-05-08 16:58:09 UTC
  • Revision ID: package-import@ubuntu.com-20140508165809-7tz9dhu5pvo5wy25
Tags: upstream-0.4.1~dfsg
Import upstream version 0.4.1~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
% This script generates a sqrt(j k) pre-equalization filter 
 
2
% for Wave Field Synthesis
 
3
%
 
4
% S.Spors
 
5
% Deutsche Telekom Laboratories
 
6
% 9th Mai 2008
 
7
 
 
8
% ===== parameters ========================================================
 
9
 
 
10
% sampling frequency of filter
 
11
f_s = 48000;
 
12
 
 
13
% aliasing frequency of system (= upper frequency limit of equalization filter)
 
14
f_al = 1500;
 
15
 
 
16
% lower frequency limit of filter (= frequency when subwoofer is active)
 
17
f_sw = 120;
 
18
 
 
19
% number of coefficients for filter
 
20
Nfilt=128;
 
21
 
 
22
 
 
23
% ===== variables =========================================================
 
24
f = linspace(0,f_s/2,441*10);
 
25
 
 
26
idx_al=max(find(f<f_al));
 
27
idx_sw=max(find(f<f_sw));
 
28
 
 
29
H = ones(1,length(f));
 
30
 
 
31
 
 
32
% -------------------------------------------------------------------------
 
33
% computation of pre-equalization filter
 
34
% -------------------------------------------------------------------------
 
35
 
 
36
% desired response
 
37
H(1:idx_al) = sqrt(2*pi*f(1:idx_al))./sqrt(2*pi*f_al);
 
38
H(1:idx_sw) = H(idx_sw)*ones(1,idx_sw);
 
39
 
 
40
% compute filter
 
41
h = firls(Nfilt,2*f/f_s,H);
 
42
 
 
43
% truncate length to power of 2
 
44
h = h(1:end-1);
 
45
 
 
46
% -------------------------------------------------------------------------
 
47
% plot resulting filter characteristics
 
48
% -------------------------------------------------------------------------
 
49
 
 
50
Hfilt=fftshift(fft(h));
 
51
Hfilt=Hfilt(Nfilt/2+1:end);
 
52
f2 = linspace(0,f_s/2,length(Hfilt));
 
53
 
 
54
figure
 
55
plot(f,20*log10(abs(H)));
 
56
hold on
 
57
plot(f2,20*log10(abs(Hfilt)),'ro-');
 
58
hold off
 
59
 
 
60
grid on
 
61
xlabel('frequency -> [Hz]');
 
62
ylabel('magnitude response -> [dB]');
 
63
legend('desired response','filter response','Location','SouthEast');
 
64
axis([0 2*f_al -20 2]);
 
65
 
 
66
 
 
67
figure
 
68
freqz(h,1,[],f_s)
 
69
 
 
70
% -------------------------------------------------------------------------
 
71
% save filter coefficients
 
72
% -------------------------------------------------------------------------
 
73
fname = sprintf('wfs_prefilter_%d_%d_%d.wav',f_sw,f_al,f_s);
 
74
disp(['Wrote pre-equalization filter into file: ' fname]);
 
75
wavwrite(h,f_s,fname);
 
76