demo_bat
May 2016 Revised April 2019, March 2022
Contents
Start
clear % close all set_plot_defaults addpath transforms I = sqrt(-1); rmse = @(err) sqrt(mean(abs(err(:)).^2)); % Set random number generator for reproducibility rng('default') rng(1) dB = @(x) 20*log10(abs(x));
Load signal
s = load('data/bat.txt'); N = length(s); % N : signal length n = 1:N; Fs = 1; T = N; figure(1) clf plot(s)

Make noisy signal
% y : signal + noise
sigma = 0.05;
y = s + sigma * randn(size(s));
figure(1)
clf
plot(y)

Define STFT (hop by 25%)
with A A' = I
% STFT - parameters R = 2^6; % R : frame length Nfft = R; M = 4; % 4-times oversampling (hop size is 25%) K = 2; % window shape parameter [A_, AH, normA] = MakeTransforms('STFT2', N, [R M K Nfft]); A = @(x) A_(x).';
Reconstruction error = 0.000000 Energy ratio = 1.000000
STFT of noisy data
S = AH(s); Y = AH(y); dBlim = [-50 10]; figure(1), clf subplot(2, 2, 1) displaySTFT(S, Fs, T, dBlim) title('STFT of noise-free data') colorbar subplot(2, 2, 2) displaySTFT(Y, Fs, T, dBlim) title('STFT of noisy data') colorbar

Denoising using L1 norm
lam_L1 = 0.03; c_L1 = sparseLS_L1(y, A, AH, 1, lam_L1); x_L1 = A(c_L1); rmse_L1 = rmse(x_L1 - s) figure(1), clf % displaySTFT(c_L1, Fs, T, dBlim) displaySTFT(c_L1, Fs, T) title('SSA-L1 STFT coefficients') colorbar
rmse_L1 = 0.0262

Denoising using GMC penalty
lam_GMC = 0.051; gamma = 0.7; c_GMC_ = sparseLS_GMC(y, A, AH, 1, lam_GMC, gamma); figure(1), clf % displaySTFT(c_GMC_, Fs, T, dBlim) displaySTFT(c_GMC_, Fs, T) title('SSA-GMC - STFT coefficients') colorbar

Altnerate algorithm
c_GMC = sparseLS_GMC_ver2(y, A, AH, 1, lam_GMC, gamma); err = c_GMC - c_GMC_; mean(abs(err(:))) / mean(abs(c_GMC_(:))) x_GMC = A(c_GMC); rmse_GMC = rmse(x_GMC - s)
ans = 0.0034 rmse_GMC = 0.0260
fprintf('RMSE:\n') fprintf('SSA-L1 : %.4f\n', rmse_L1) fprintf('SSA-GMC : %.4f\n', rmse_GMC)
RMSE: SSA-L1 : 0.0262 SSA-GMC : 0.0260
v{1} = s; v{2} = y; v{3} = x_L1; v{4} = x_GMC; V{1} = S; V{2} = Y; V{3} = c_L1; V{4} = c_GMC; strs{1} = 'True signal'; strs{2} = 'Noisy signal'; strs{3} = 'Denoising using L1 norm'; strs{4} = 'Denoising using GMC penalty'; axtxt{1} = ' '; axtxt{2} = ' '; axtxt{3} = sprintf('RMSE = %.3f', rmse(x_L1 - s)); axtxt{4} = sprintf('RMSE = %.3f', rmse(x_GMC - s)); dBlim = [-50 0]; Fs = 1/7 * 1e+6; t = (1:N)/Fs; figure(1) clf for i = 1:4 subplot(4, 2, 2*i - 1) plot(t*1e3, v{i}) % xlim([1500 1800]) ylim([-1 1]*0.3) xlim([0 N/Fs*1e3]) title(strs{i}) xlabel('Time (ms)') set(gca, 'ytick', -.3:.3:.3); set(gca, 'xtick', 0:1:3); h1 = text(0.02, 0.98, axtxt{i}, ... 'units', 'normalized', ... 'horizontalalignment', 'left', ... 'verticalalignment','top', ... 'backgroundColor','none' ... ); % 'fontsize', font_size ... subplot(4, 2, 2*i ) displaySTFTb(V{i}(:, 2:end-1), Fs, N/Fs*1e3) title('Time-frequency profile (dB)') colorbar end orient tall print -dpdf -fillpage figures/demo_bat
