Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[2f5a82]: demos / demo_audioshrink.m Maximize Restore History

Download this file

demo_audioshrink.m    103 lines (82 with data), 2.5 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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
%DEMO_AUDIOSHRINK Decomposition into tonal and transient parts
%
% This demos shows how to do audio coding and "tonal + transient"
% decomposition using group lasso shrinkage of two |wmdct| transforms
% with different time-frequency resolutions.
%
% The signal is transformed using two orthonormal |wmdct| bases.
% Then group lasso shrinkage is applied to the two transforms
% in order to:
%
% * select fixed frequency lines of large |wmdct| coefficients on the
% wide window |wmdct| transform
%
% * select fixed time lines of large |wmdct| coefficients on the
% narrow window |wmdct| transform
%
% The corresponding approximated signals are computed with the
% corresponding inverse, |iwmdct|.
%
% .. figure::
%
% Plots and time-frequency images
%
% The upper plots in the figure show the tonal parts of the signal, the
% lower plots show the transients. The TF-plots on the left are the
% corresponding wmdct coefficients found by appropriate group lasso
% shrinkage
%
% Corresponding reconstructed tonal and transient sounds may be
% listened from arrays rec1 and rec2 (sampling rate: 44.1 kHz)
%
% Load audio signal and add noise
% -------------------------------
% Use the 'glockenspiel' signal.
sig=gspi;
fs=44100;
% Shorten signal
siglen = 2^16;
sig = sig(1:siglen);
% Add Gaussian white noise
nsig = sig + 0.01*randn(size(sig));
% Tonal layer
% -----------
% Create a WMDCT basis with 256 channels
F1=frametight(frame('wmdct','gauss',256));
% Group lasso and invert
c1 = franagrouplasso(F1,nsig,0.8,'soft','freq');
rec1 = frsyn(F1,c1);
% Transient layer
% ---------------
% Create a WMDCT basis with 32 channels
F2=frametight(frame('wmdct','gauss',32));
c2 = franagrouplasso(F2,nsig,0.5,'soft','time');
rec2 = frsyn(F2,c2);
% Plots
% -----
% Dynamic range for plotting
dr=50;
xplot=(0:siglen-1)/fs;
figure(1);
subplot(2,2,1);
plot(xplot,rec1);
xlabel('Time (s)');
axis tight;
subplot(2,2,2);
plotframe(F1,c1,fs,dr);
subplot(2,2,3);
plot(xplot,rec2);
xlabel('Time (s)');
axis tight;
subplot(2,2,4);
plotframe(F2,c2,fs,dr);
% Count the number of non-zero coefficients
N1=sum(abs(c1)>0);
N2=sum(abs(c2)>0);
p1 = 100*N1/siglen;
p2 = 100*N2/siglen;
p=p1+p2;
fprintf('Percentage of retained coefficients: %f + %f = %f\n',p1,p2,p);
disp('To play the original, type "soundsc(sig,fs)"');
disp('To play the tonal part, type "soundsc(rec1,fs)"');
disp('To play the transient part, type "soundsc(rec2,fs)"');