-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinvspecgram.m
54 lines (42 loc) · 1007 Bytes
/
invspecgram.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
53
54
function res = invspecgram(B,NFFT,Fs,WINDOW,NOVERLAP)
% res = invspecgram(B,NFFT,Fs,WINDOW,NOVERLAP)
% All parameters are like specgram...
% Written by Niels Henrik Pontoppidan
if ((nargin<2)|isempty(NFFT))
NFFT=256;
end
if ((nargin<3)|isempty(Fs))
Fs=2;
end
if ((nargin<4)|isempty(WINDOW))
WINDOW=hanning(NFFT);
end
if ((nargin<5)|isempty(NOVERLAP))
NOVERLAP=length(WINDOW)/2;
end
if ((nargin<6)|isempty(NR))
NR=0;
end
if length(NFFT)==1
[N,M] = size(B);
Next=NFFT-N;
ext=conj(B(Next+1:-1:2,:));
Bfull = [B;ext];
%[size(Bfull) NOVERLAP]
idft = real(ifft(Bfull));
WL=length(WINDOW);
idft=idft(1:WL,:);
W=repmat(WINDOW,1,M);
SPACING=WL-NOVERLAP;
IDFT=zeros(M*SPACING+NOVERLAP,1);
Wind=IDFT;
for m=1:M
idx=( (m-1)*SPACING+(1:WL))';
IDFT(idx)=IDFT(idx)+idft(:,m);
Wind(idx)=Wind(idx)+W(:,m);
end
Wind(1:round(WL/2))=max(1,Wind(1:round(WL/2)));
Wind(end-round(WL/2):end)=max(1,Wind(end-round(WL/2):end));
res=IDFT./Wind;
else
end