0% found this document useful (0 votes)
4 views8 pages

MATLAB and Python Audio Denoising Techniques

The document contains MATLAB and Python code for audio denoising using Fourier transforms. It also includes mathematical derivations related to Fourier series and partial differential equations (PDEs). Additionally, it discusses boundary conditions and Laplace transforms in the context of solving differential equations.

Uploaded by

Alireza
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

MATLAB and Python Audio Denoising Techniques

The document contains MATLAB and Python code for audio denoising using Fourier transforms. It also includes mathematical derivations related to Fourier series and partial differential equations (PDEs). Additionally, it discusses boundary conditions and Laplace transforms in the context of solving differential equations.

Uploaded by

Alireza
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

‫حل سواﻻت‬

1.
MATLAB:
[audio, FS] = audioread('MYSOUND.mp3');

N = length(audio);
s = fft(audio);

hfreq = 1200;

f = (0:N-1)*(FS/N);
filter = abs(f) < hfreq;
S = s .* filter';
denoised_sound = real(ifft(S));

figure;
subplot(2, 1, 1);
plot((0:N-1)/FS, audio);
title('Original Sound');
xlabel('Time (s)');
ylabel('Amplitude');

subplot(2, 1, 2);
plot((0:N-1)/FS, denoised_sound);
title('Denoised Sound');
xlabel('Time (s)');
ylabel('Amplitude');

audiowrite("Denoised [Link]",denoised_sound,FS);
PYTHON
import librosa
import numpy as np
from [Link] import write
import [Link] as plt

file_path = "H_2.mp3"
samples, sampling_rate = [Link](file_path, sr=None, mono=True)

window_size = 2048
hop_length = window_size // 2
threshold_multiplier = 0.5
hann_window = [Link](window_size)
reconstructed_signal = [Link](len(samples))

for i in range(0, len(samples) - window_size, hop_length):


windowed_signal = samples[i:i + window_size] * hann_window
fhat = [Link](windowed_signal)
PSD = [Link](fhat) ** 2
threshold = [Link](PSD) * threshold_multiplier
soft_indices = PSD > threshold
fhat_filtered = fhat * (soft_indices + (1 - soft_indices) * 0.1)
filtered_window = [Link](fhat_filtered).real * hann_window
reconstructed_signal[i:i + window_size] += filtered_window

reconstructed_signal = np.int16(reconstructed_signal / [Link]([Link](reconstructed_signal)) * 10000)

write("clean_audio_fft_advanced.wav", sampling_rate, reconstructed_signal)

[Link](figsize=(16, 12))
[Link](2, 1, 1)
[Link](samples[:5000], color='red', label='Noisy Signal')
[Link]('Original Signal (Noisy)')
[Link](2, 1, 2)
[Link](reconstructed_signal[:5000], color='blue', label='Filtered Signal')
[Link]('Filtered Signal')
[Link]()
2.
𝑓(𝑥) = |𝑥|

‫[ سري فوريه‬−π, π]

a
f(x) = + [a cos (nx) + b sin (nx)]
2
2
a = xdx = π
π

2 2 xsin(nx) 1 2 2((−1) − 1) 0 𝑛 = 2𝑘
a = xcos(nx) dx = − sin(nx) dx = cos(nx)| = = −4
π π n n n π n π 𝑜. 𝑤.
n π

b =0

π −4 π −4 1 π
f(x) = + cos(𝑛𝑥) 0= + → =
2 (2n − 1) π 2 (2n − 1) π (2n − 1) π 8

1 1 1 π π
= 𝑆 𝑆= 𝑆+ →𝑆=
(2n) 4 4 8 6

I.
‫ در معادله‬u (x, t) =X(x)T(t) ‫( جاگداري‬١ ‫مرﺣﻠه‬

X(x)T (t) = 𝑐 X (x)T(t) ⟹ ÷ 𝑐 X(x)T(t) ⟹ = =α

‫ و ﺣل معادله‬α ‫ مشخص كردن عﻼمت‬:(٢ ‫مرﺣﻠه‬

u (0, t) = u (L, t) =0 ⟹X (0) =X(L)=0 ⟹ α < 0 ⇒ X (x) = sin x ⟹ α = −( )

T ‫( ﺣل معادله‬٣ ‫مرﺣﻠه‬
1 nπ nπ nπct nπc
T =− ⟹T +c T = 0 ⟹ T (t) = A Cos t + B Sin t
c L L L L

u(x, t) = ∑ 𝑋 𝑇 ‫( ﻧوﺷﺘﻦ‬4 ‫مرﺣﻠه‬

nπc nπc nπ
u(x, t) = A Cos t + B Sin t Sin x
L L L

u(x, 0) = 10Sin( ) = ∑ A Sin x → A = ∫ 10Sin( )Sin xdx

2 1 πx nπx πx nπx 1 πxL + 10nπx πxL − 10nπx


A = − cos( + ) − cos( − ) =− cos( ) − cos( )
L 2 10 L 10 L 𝐿 10L 10L

nπc nπc nπc nπc nπ


u (x, t) = − A Sin t+ B Cos t Sin x
L L L L L

nπc nπ
u (x, 0) = B Sin x=0
L L

B =0

u(x, t)‫ در‬A ‫( جاگذاري‬٥‫مرﺣﻠه‬

nπc nπ
u(x, t) = A Cos t Sin x
L L
II.

‫ﺷرط مرزي همگﻦ است و ﻧيازي به تغيير مﺘغيير براي همگﻦ كردن ﺷرط مرزي ﻧدازيم‬

1T nπ
=− ⟹ T (t) = A e
kT L

‫ جداسازي معادله همگﻦ‬٢ ‫ و‬١ ‫( گام‬١ ‫مرﺣﻠه‬

1T X
u (x, t) = X(x)T(t) ⟹ X(x)T (t) = kX (x)T(t) ⟹ ÷ kX(x)T(t) ⟹ = = α , α = −λ
kT x
X + 𝜆 x = 0 ⟹ X(x) = asinλx + bcosλx
nπ nπ
x(0) = x(L) = 0 ⟹ λ = ⟹ X(x) = sin x ⟹ L = π ⟹ X(x) = sin(nx)
L L
PDE ‫( بسط دادن جمﻠه ﻧاهمگﻦ‬٢ ‫مرﺣﻠه‬

2 𝑛=3
2 sin 3x = A (t)sin 𝑛x ⟹ A (t) =
0 𝑛≠3

u(x, t) = ∑ 𝑋 𝑇 ‫( تشکيل‬٣ ‫مرحله‬

T (t)sin nx = − n T(t)sin nx + A (t)sin nx

2
T + 9kT = 2 𝑛 = 3 ⟹ 𝑇 (𝑡) = +𝐷 𝑒
T + kn T = A (t) ⟹ 9𝑘
T + k n T = 0 𝑛 ≠ 3 ⟹ 𝑇 (𝑡) = 𝐶 𝑒

T + 9kT = 2 ⟹ r(x) = e∫ = 𝑒 ⟹ (T + 9kT = 2) × 𝑒 ⟶ (T 𝑒 ) = ∫ 2𝑒 𝑑𝑡

du 2 2 2 2
u = 9kt ⇒ = dt →= ∫ 𝑒 𝑑𝑢 = 𝑒 + 𝑐 → (T 𝑒 = 𝑒 +𝐷 )÷𝑒 →T = +𝐷 𝑒
9𝑘 9𝑘 9𝑘 9𝑘 9𝑘

2
u(x, t) = 𝐶 𝑒 sin(nx) + ( +𝐷 𝑒 )sin3x
9𝑘

2
u(x, 0) = sin(2x) = 𝐶 sin(nx) + ( + 𝐷 )sin3x = 𝐴 sin(nx)
9𝑘
𝐶 𝑛≠3
2 4 sin(nπ) 2
A = sin(2x) sin(nx)dx = →A = 2 →𝐷 + = 0.041
𝜋 π (𝑛 − 4) 𝐷 + 𝑛=3 9𝑘
9𝑘
III.

‫موجود در جزوه‬
4.

X ‫تبديل فوريه ﻧمايي به دليل وجود بازه‬

u + 2u + u = u → F(u ) + 2F(u ) + F(u) = F(u )

F{u(x, t)} = U(ω, t)

F(u ) = −ω U

F(u) = U

F(u ) = U

F(u ) = U

:U ‫ بدست آمده و‬ODE ‫ﺣل‬

U + 2U + (1 + ω )u = 0 → s + 2s + (1 + ω ) = 0

−2 ± 4 − 4 1 + ω2
𝑆= = −1 + −ω = −1 ± 𝑖ω
2

U(ω, t) = e (A(ω) cos(𝜔𝑡) + B(ω) sin(ωt))

:‫جاگذاري ﺷرايط مرزي و محاسبه ضريب‬

sinx sinx 1 sinϑ 1 sinϑ


u(x, 0) = → U(ω, 0) = F{ }= e dϑ = (cos(ωϑ) − isin(ωϑ))dϑ
x x √2𝜋 ϑ √2𝜋 ϑ

1 sinϑ sinϑ
( cos(ωϑ)dϑ − isin(ωϑ)dϑ)
√2𝜋 ϑ ϑ
sin(ϑt)cos(ωt) = 12 sin (ω + ϑ)t − sin (ω − ϑ)t
sin(ϑt)sin(ωt) = 12[cos((ω − ϑ)t) − cos((ω + ϑ)t)]
1
= 𝑒 𝑑𝑠
𝜗

1
( sinϑ 𝑐𝑜𝑠(𝜔𝜗)𝑒 𝑑𝜗 − i sinϑ 𝑠𝑖𝑛(𝜔𝜗)𝑒 𝑑𝜗)
√2𝜋

= rect(ω)
𝜋
= u (x, 0) = − → U (ω, 0) = − rect(ω)
2

U(ω, 0) = A(ω)= rect(ω)

𝜋 𝜋
U (ω, 0) = −1 × rect(ω) + B(ω) = − rect(ω) → B(ω) = 0
2 2

𝜋
U(ω, t) = e rect(ω)cos(𝜔𝑡)
2

𝜋
u(x, t) = F e rect(ω)cos(𝜔𝑡) =
2

5.
G +G = δ(x − ξ)δ(t − τ)
L{G(x, y, ξ, τ)} = G(x, y, ξ, τ)
LG = S G − sG(x, y, ξ, τ) = s G
L{G } = G
e
L{δ(t − τ)} = e →s G+G = δ(x − ξ)
𝑠
:x ‫گرفﺘﻦ تبديل فوريه ﻧسبت به‬
𝐹 G(x, y, ξ, τ) = G(ω, y, ξ, τ)
𝐹 G = (iω) G = − ω G
1 1 ξ −e e ξ
F{δ(x − ξ)} = 𝑒 δ(ϑ − ξ) 𝑑𝜗 = e ⟹s G−ω G=
√2𝜋 √2π s
−𝑒 𝑒 ξ −𝑒 𝑒 ξ 1 1
G= = ( − )
𝑠 (𝑠 − 𝜔 ) 𝜔 𝑆 𝑠 −𝜔
‫ﻻپﻼس وارون‬
e ξ 1
L G = (u (t)t − u (t)sinhωt)
ω ω

You might also like