Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2020-101
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sachith Fernando
2020-101
Commits
12d23d82
Commit
12d23d82
authored
Nov 05, 2020
by
LiniEisha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reformatting noiseRemove.py
parent
3a879725
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
28 deletions
+35
-28
LectureSummarizingApp/noiseRemove.py
LectureSummarizingApp/noiseRemove.py
+35
-28
No files found.
LectureSummarizingApp/noiseRemove.py
View file @
12d23d82
import
numpy
as
np
import
scipy
as
sp
import
numpy
as
n
um
p
import
scipy
as
s
i
p
from
scipy.io.wavfile
import
read
from
scipy.io.wavfile
import
write
from
scipy
import
signal
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
m
plt
#get_ipython().magic('matplotlib inline')
(
Frequency
,
array
)
=
read
(
'lectures/Lecture01.wav'
)
len
(
array
)
plt
.
plot
(
array
)
plt
.
title
(
'Original Signal Spectrum'
)
plt
.
xlabel
(
'Frequency(Hz)'
)
plt
.
ylabel
(
'Amplitude'
)
m
plt
.
plot
(
array
)
m
plt
.
title
(
'Original Signal Spectrum'
)
m
plt
.
xlabel
(
'Frequency(Hz)'
)
m
plt
.
ylabel
(
'Amplitude'
)
FourierTransformation
=
s
p
.
fft
(
array
)
fourierTransformation
=
si
p
.
fft
(
array
)
scale
=
sp
.
linspace
(
0
,
Frequency
,
len
(
array
))
scale
=
s
i
p
.
linspace
(
0
,
Frequency
,
len
(
array
))
plt
.
stem
(
scale
[
0
:
5000
],
np
.
abs
(
F
ourierTransformation
[
0
:
5000
]),
'r'
)
plt
.
title
(
'Signal spectrum after FFT'
)
plt
.
xlabel
(
'Frequency(Hz)'
)
plt
.
ylabel
(
'Amplitude'
)
mplt
.
stem
(
scale
[
0
:
5000
],
nump
.
abs
(
f
ourierTransformation
[
0
:
5000
]),
'r'
)
m
plt
.
title
(
'Signal spectrum after FFT'
)
m
plt
.
xlabel
(
'Frequency(Hz)'
)
m
plt
.
ylabel
(
'Amplitude'
)
GuassianNoise
=
np
.
random
.
rand
(
len
(
F
ourierTransformation
))
guassianNoise
=
nump
.
random
.
rand
(
len
(
f
ourierTransformation
))
NewSound
=
G
uassianNoise
+
array
NewSound
=
g
uassianNoise
+
array
write
(
"New-Sound-Added-With-Guassian-Noise.wav"
,
Frequency
,
NewSound
)
b
,
a
=
signal
.
butter
(
5
,
1000
/
(
Frequency
/
2
),
btype
=
'highpass'
)
u
,
v
=
signal
.
butter
(
5
,
1000
/
(
Frequency
/
2
),
btype
=
'highpass'
)
filteredSignal
=
signal
.
lfilter
(
b
,
a
,
NewSound
)
plt
.
plot
(
filteredSignal
)
# plotting the signal.
plt
.
title
(
'Highpass Filter'
)
plt
.
xlabel
(
'Frequency(Hz)'
)
plt
.
ylabel
(
'Amplitude'
)
filteredSignal
=
signal
.
lfilter
(
u
,
v
,
NewSound
)
c
,
d
=
signal
.
butter
(
5
,
380
/
(
Frequency
/
2
),
btype
=
'lowpass'
)
# ButterWorth low-filter
newFilteredSignal
=
signal
.
lfilter
(
c
,
d
,
filteredSignal
)
# Applying the filter to the signal
plt
.
plot
(
newFilteredSignal
)
# plotting the signal.
plt
.
title
(
'Lowpass Filter'
)
plt
.
xlabel
(
'Frequency(Hz)'
)
plt
.
ylabel
(
'Amplitude'
)
# plotting the signal.
mplt
.
plot
(
filteredSignal
)
mplt
.
title
(
'Highpass Filter'
)
mplt
.
xlabel
(
'Frequency(Hz)'
)
mplt
.
ylabel
(
'Amplitude'
)
write
(
"file.wav"
,
Frequency
,
np
.
int16
(
newFilteredSignal
/
np
.
max
(
np
.
abs
(
newFilteredSignal
))
*
32767
))
\ No newline at end of file
# ButterWorth low-filter
x
,
y
=
signal
.
butter
(
5
,
380
/
(
Frequency
/
2
),
btype
=
'lowpass'
)
# Applying the filter to the signal
newFilteredSignal
=
signal
.
lfilter
(
x
,
y
,
filteredSignal
)
# plotting the signal.
mplt
.
plot
(
newFilteredSignal
)
mplt
.
title
(
'Lowpass Filter'
)
mplt
.
xlabel
(
'Frequency(Hz)'
)
mplt
.
ylabel
(
'Amplitude'
)
write
(
"removed.wav"
,
Frequency
,
nump
.
int16
(
newFilteredSignal
/
nump
.
max
(
nump
.
abs
(
newFilteredSignal
))
*
32767
))
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment