From 99987da72c5aea3dcfc42b2786a87d99d765fa23 Mon Sep 17 00:00:00 2001 From: rainydaysavings Date: Mon, 28 Dec 2020 02:13:56 +0000 Subject: [PATCH] Tentative noise cancelling with FFT. PSD might help in identifying chirp sounds. --- TP3/DiogoEliseu_TP3_8.m | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 TP3/DiogoEliseu_TP3_8.m diff --git a/TP3/DiogoEliseu_TP3_8.m b/TP3/DiogoEliseu_TP3_8.m new file mode 100644 index 0000000..ba92712 --- /dev/null +++ b/TP3/DiogoEliseu_TP3_8.m @@ -0,0 +1,34 @@ +%% clean environment +clear; close all; clc + +%% read input +[signal, fs] = audioread("Canto1.mp3"); + +%% Compute the FFT +signal_length = length(signal); +fhat = fft(signal, signal_length); +PSD = fhat.*conj(fhat)/signal_length; % Power spectrum density +%[S, freq, T, PSDlel] = spectrogram(signal, 128, 96, 128, Fs); +% signal, window, noverlap, nfft, fs +freq_vector = linspace(1, fs, signal_length); +L = 1:floor(signal_length/2); + +cutoff_indices = abs(PSD)>0.002; +PSD_clean = PSD.*cutoff_indices; +fhat_filtered = cutoff_indices.*fhat; +signal_filtered = ifft(fhat_filtered); + +figure(1) +plot(PSD) + +figure(2) +plot(PSD_clean) + +figure(3) +plot(signal) + +figure(4) +plot(signal_filtered) + +%% output +audiowrite('restored.flac', signal_filtered, fs); \ No newline at end of file