Tentative noise cancelling with FFT. PSD might help in identifying chirp sounds.

This commit is contained in:
rainydaysavings 2020-12-28 02:13:56 +00:00
parent 459ba23074
commit 99987da72c
1 changed files with 34 additions and 0 deletions

34
TP3/DiogoEliseu_TP3_8.m Normal file
View File

@ -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);