[77a22a]: demos / demo_nsdgt.m Maximize Restore History

Download this file

demo_nsdgt.m    90 lines (72 with data), 2.1 kB

 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
%DEMO_NSDGT Nonsationary Gabor transform demo
%
% This script sets up a nonstationary Gabor frame with the specified
% parameters, computes windows and corresponding canonical dual windows
% and a test signal, and plots the windows and the energy of the
% coefficients.
%
% .. figure::
%
% Windows + dual windows
%
% This figure shows the window functions used and the corresponding
% canonical dual windows.
%
% .. figure::
%
% Spectrogram (absolute value of coefficients in dB)
%
% This figure shows a (color coded) image of the nsdgt coefficient
% modulus.
%
% See also: nsdgt, insdgt, nsgabdual
disp(['Type "help demo_nsdgt" to see a description of how this example',...
' works.']);
% Setup parameters and length of signal.
Ls=965; % Length of signal.
N=16; % Number of time positions
% Define a set of windows with length growing linearly. The step beetween
% to consecutive windows also grows linearly.
M=round(linspace(40,200,N)');
a=cumsum(round(M/2));
a=a-a(1);
a_new=round(M/2);
g={};
for ii=1:length(M)
g{ii}=firwin('hann',M(ii));
end
% Compute corresponding dual windows
gd=nsgabdual(g,a_new,Ls);
% Plot them
figure(1);
color = ['b', 'r'];
for ii = 1:length(a)
subplot(2,1,1);
hold on;
plot(a(ii)-1-floor(M(ii)/2)+(1:M(ii)), fftshift(g{ii}),...
color(rem(ii,2)+1));
subplot(2,1,2);
hold on;
plot(a(ii)-1-floor(M(ii)/2)+(1:M(ii)), fftshift(gd{ii}),...
color(rem(ii,2)+1));
end
subplot(2,1,1);
title('Analysis windows');
xlabel('Time index');
subplot(2,1,2);
title('Dual synthesis windows');
xlabel('Time index');
% Define a sinus test signal.
f=sin(2*pi*0.3*(0:Ls-1)');
% Calculate coefficients.
c=nsdgt(f,g,a_new,M);
% Plot corresponding spectrogram
figure(2);
plotnsdgt(c,a,'dynrange',100);
title('Spectrogram of test signal')
% Test reconstruction
f_r=insdgt(c,gd,a_new,Ls);
% Print relative error of reconstruction.
rec_err = norm(f-f_r)/norm(f);
fprintf(['Relative error of reconstruction (should be close to zero.):'...
' %e \n'],rec_err);