File: Bandpass.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (35 lines) | stat: -rw-r--r-- 1,151 bytes parent folder | download | duplicates (7)
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
function w=Bandpass(n,fLow,fHigh)
% w=Bandpass(n,fLow,fHigh) returns a 1xn window, a band-pass filter. The
% elements represent gain at each freq, uniformly spaced from -1 to 1 of
% Nyquist frequency. fLow and fHigh are the positive cut-off frequencies
% on this scale. We pass frequencies in the interval [fLow,fHigh). The
% asymmetric use of bounds guarantees that complementary filters will add
% to 1: Bandpass(n,0,f)+Bandpass(n,f,Inf)==ones(1,n). If fHigh is omitted
% it's assumed to be Inf. Also see Bandpass2.

% 1994   dgp       Wrote it
% 7/3/96 jny & dgp Replaced erroneous formula for freqs by FREQSPACE. 

if nargin<2 || nargin>3
	error('Usage: w=Bandpass(n,fLow,[fHigh])')
end
if nargin<3
	fHigh=Inf;
end;
if n<2 | n~=floor(n)
	error('First arg ''n'' must be an integer greater than 1')
end
if fLow<0 | fHigh<0
	error('Frequencies can''t be negative')
end
if rem(n,2) % copied from FREQSPACE
	t=-1+1/n:2/n:1-1/n;
else
	t=-1    :2/n:1-2/n;
end
t=abs(t);
w=ones(size(t));			% start with all-pass filter
d=find(t<fLow | t>=fHigh);	% find out-of-band frequencies
if ~isempty(d)
	w(d)=zeros(size(d));	% zero the gain at those frequencies
end