okay let's think about an example of an
LTI system I talked about in LTI system
being a filter well let's actually think
about a filter we're going to think
about filtering some audio signal so
here is the audio signal it's someone
clapping and a chair but there's this
awful high-pitched scream over the top
of it if we plot the sound amplitude
like this then we can see the claps
carrying at regular intervals the
high-pitched scream is a solid block of
blue so this is the the amplitude of
sound as a function of time we can't see
the individual oscillations because
they're also too close together now as
we go through the next few slides I'm
going to paste up the Mathematica
commands I use to generate these plots
is it horrible sound again I first
import a sound file called noisy claps
wave which I'll make available and I use
the import command and I'm going to give
this the name claps and this is a sound
object in Mathematica it's not a table
of data but it's actually a sound object
an audio object I'm also going to define
some plot options these are just still
tells Mathematica how I want my plots to
look with the aspect ratio let's kind of
stuff and then to make this plot I use a
command called audio plot which plots
the the time series of some audio object
audio plot of collapse
including the plot options and then
labeling the axes okay this time series
a little hard to interpret let's look at
a spectrum I can use a command called
periodic Graham which takes a spectrum a
the energy spectrum so it's the square
of the Fourier transform just looking at
the positive frequencies and plots it so
I'm taking the period a gram of claps
with thumb some labels on my axes and
the and the vertical axis here is energy
it's a decibel scale and shows us how
much energy we have in each of our
frequencies and we can say there's a
massive amount of energy at this big
spike here at six and a half thousand
Hertz so that's the frequency of this
audio tone that we can hear and we can
see that you know we're down and around
you know minus 30 DB here and up to plus
30 DB so it's 60 DB different so that is
a factor
million times larger a million times
more energy at this frequency compared
to all the other frequencies now this
the spectrum this plot of the the
spectral density is taken over the
entire time series like this but we can
see that you know that the sound is
changing as a function of time we have
the collapse these regular regular
intervals it's a really useful technique
is to divide the sound file up into
shorter intervals and take a spectrum
over lots of little short intervals and
then paste the different spectra
together so we can see how the spectrum
of the sound changes as a function of
time so this is like an average over the
entire file but we can also do this
where we divided up to be you know maybe
a hundred different spectra calculated
per second and we can see that when you
have a clap we have a lot of different
frequencies and every time is a clap
where this wide spread of frequencies
from 0 up to the highest frequency in
our file which is 13,000 Hertz and where
this big long tone here at six and a
half thousand Hertz which is all the way
through of course a clap is some kind of
approximation for a delta function so
you expect the Delta function should
have a wide range of frequencies and
indeed that's what we see where is this
constant tone appears to be more or less
a single frequency well you can also see
the cheering here that's what this
little bit of the pattern here is the
color density so the depth of the color
here indicates a higher power in the pin
in each frequency okay and the way you
you plot that isn't using a command
called spectrogram all right now the
thing you want to do next is try and
filter out this big spike this big
horrible screechie spike at six and a
half thousand Hertz I mentioned
previously the highest frequency here is
thirteen thousand Hertz which is telling
us that the Nyquist frequency of
thirteen thousand Hertz which tells us
also that the sampling frequency of his
file is 26 thousand Hertz so it's lower
than a typical audiophile but it makes
it a little easier to process let's look
at the straight Fourier transform of our
audio file now because we're not going
to filter the spectrum we need to filter
the actual four-year data
because if you remember our LTI system
we have the Fourier spectrum going in
and we're going to multiply it by some
filter function or transfer function G
of Omega to get our output so now we
could design our filter so to do that
we're gonna look at the Fourier
transform so we've got a real part here
and an imaginary part and we see that
the real part has a maximum amplitude of
like plus minus 1/2 the imaginary part
on the other hand has these huge spikes
at six and a half thousand Hertz and
negative six and a half thousand Hertz
the plot of the frequencies here you can
see is done in the default way for the
computer to think about the Fourier
transform so it goes from 0 to plus the
microcosm knockers frequency and back up
to zero the first data point here is the
zero term that's where the tells you how
much amplitude you have at zero
frequency the last point here is a
slight negative frequency just below
zero and the reason why I mentioned this
becomes important in a bit ok and we can
also tell that our single we're trying
to filter is actually a sine wave from
we can tell because it's all in the
imaginary component if it were a cosine
wave if it would all be in the real
component of it's somewhere in between
sine and cosine we'd have a bit of
amplitude in each okay so the thing
we're trying to filter out is a sine
wave at six and a half thousand Hertz
and first of all before I show you what
we can do different filtering I'll show
you how I've plotted this data so the
Clapp data is the the actual data
extract from the audio file and the way
I do that is I use a command called
audio data on claps so it collapses the
audio object audio data extracts it as
just a table of data so vectors of data
and this flatten command removes some of
the curly brackets at Mathematica puts
everywhere the Fourier transform I take
by using the command for ear for ear of
clap data and it's this is what I'm
plotting here the real part of ft clap
data and the measuring part of ft clap
data most of the gump that you see here
is actually dedicated to getting axes
labels on these plots from 0 up to plus
13 the minus 13 back
to zero because it's not something that
Mathematica does lightly so I've had to
do that manually so do it by hand if you
like so I've got some labels here that I
use to to label the the x-axis anyway
here is the command list line plot for
plotting the real part of ft clap data
and list line plot for plotting the
imaginary part of te clap data okay
onwards what sort of filter do we want
well we want to have a feel for the
guess through these spikes so basically
we want to get rid of this part of the
spectrum here now this is the result
after I filtered it out the kind of
filter that I've used is basically the
dumbest one you could think of and that
is I've got a vector of ones everywhere
they're going to multiply after my
Fourier transform by except for a narrow
band of frequencies here and here where
I've set that vector to zero so when you
multiply those two things together you
just let through all the frequencies
unaffected except for these ones here
and here and are filtered out both the
real and imaginary parts to define that
that filter has a really simple idea
right just a big pile of ones you
multiply all of the the frequency
components by one except if it's here or
here and then at 0 to actually define
that filter is a little messy in
Mathematica this is how after and I've
pasted together tables of ones and zeros
of the appropriate lengths I know by
measuring it that the number of data
points I have in this data set is 96 97
thousand and 66 and so the halfway point
here up to plus thirteen thousand
kilohertz from there to there will be
48,000 533 so that's where that number
comes from I just figured out by hand
what this range of frequencies here is
which is you know from around 24 index
24,000 to 24,500 because it's a
numerical data right the numerical data
is not labeled by frequencies to a
string of numbers and the the number of
the number of numbers I have just
depends on how long it is in the
sampling rate and so I've defined
filters for the positive frequencies
sets from here to here and a frequency
for the negative part which is from here
to here I've had to offset this by 1
here this is 24,000 and to miss between
4,000 and 1
offset it by one index to account for
the fact that my zero frequency is here
whereas this one doesn't have a zero
energy goes up to a frequency just below
zero and slightly negative which I
mentioned before and the final thing I
have to do for this filter for the
negative frequencies that run from here
to here is reverse the order of the
filter to mirror images because this is
like a mirror image about this Nyquist
frequency here okay and then finally my
filter is defined by sticking together
the filter for the positive part and the
reverse of the filter for negative part
and now this is the step that I
Illustrated when I was talking about LTI
systems I take my filter which is in
this case G of Omega I multiply it by my
input which is ft clap data and here I
have the filtered output and this is
what I've plotted here plotted the real
part and the imaginary part so to get my
output the time data back again I have
to take the inverse transform of this
filtered data and yes is a note on this
this I offset that I had mentioned
previously okay so my filtered clap data
would be the inverse Fourier transform
of the filtered a filtered foreo data
I've used a command called chop here to
get rid of tiny imaginary components to
get left over from the numerical Fourier
transform and so any imaginary number
which is less than 10 to the minus 5 is
just eliminated and this gives me the
data that I can then convert into an
audio object that I can then listen to
alright and I'll mention here to create
that audio object which I'll call it
filter clap sound I've got a teller with
the sample rate is as well because
otherwise it doesn't know how to
interpret the string of numbers so in
summary then here is our input
and here is the filtered output which
has been inverse Fourier transformed and
so you can hear the the sine wave there
is basically gone but I want you to
listen to this again very very closely
turn up the volume and listen to the
sound sort of immediately preceding and
after the claps
if you listen really closely you can
hear something called a pre echo it's
like a high-pitched sound that occurs
just before the clap with it just before
the clapping just after the clap and
this pre echo is caused by the kind of
filter that we used which was likely an
upside-down top-hat filter and if you
think about what a top hat is in the
time domain you can understand where
this pre echo is coming from it's
telling you this is a bad filter to use
for audio and we'll talk a bit more
about filtering and the kinds of filters
that work a bit later in a sec in
another video
so in the context of previous discussion
about what fruit transforms can do this
example of filtering an audio signal is
this one here we start off with strange
data in this case the strange data and
the confusion is this bad noise this
spike at six and a half thousand Hertz
now if you want to get to better data
and we're trying to do it in the time
domain that would be laborious to
impossible if you are trying to remove
this signal at six and a half thousand
Hertz just by analyzing the time domain
data it's not even clear how you go
about doing it because you just look at
the amplitude as a function of time how
do you decide which bits are due to the
six-and-a-half thousand Hertz signal and
how I decide which bits are due to the
clapping so that's really hard instead
what we can do is go into the Fourier
transform domain so we go down here to
the transform data we do some simple
easy analysis where we just put a filter
around our spikes and that's easy
analysis and we can inverse transform to
get our better data with our noise or
roof