From c3dbd29cab6cdeb5387d89dbc142819a70979bab Mon Sep 17 00:00:00 2001 From: Daniel Doan Date: Wed, 8 Dec 2021 19:30:22 -0800 Subject: [PATCH] added convolution function --- src/Daniel_Doan_convolution.m | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/Daniel_Doan_convolution.m diff --git a/src/Daniel_Doan_convolution.m b/src/Daniel_Doan_convolution.m new file mode 100644 index 0000000..438a08b --- /dev/null +++ b/src/Daniel_Doan_convolution.m @@ -0,0 +1,17 @@ +function x = Daniel_Doan_convolution(f,h) + %input: two 1d arrays representing two sound signals in the time domain + %output: the convolution of the two waves, which is the inverse FT of + %FT(f)*FT(h) + %author: Daniel Doan + + %padding to ensure the entire convolution is calculated + pad = length(f) + length(h) - 1; + %take FT of f + F = fft(f, pad); + %take FT of h + H = fft(h, pad); + %multiply the two FTs + X = F .* H; + %take inverse FT of the product + x = ifft(X); +end \ No newline at end of file