| ||
Step 1: |
One of the simplest things we can do to a signal is to
scale
it (i.e. multiply it by a constant). Try:
>> out1 = .25 * sig1; Or if you're lazy:
>> sound(.25 * sig1) We can also make the signal bigger:
>> sound(4 * sig1) | |
Step 2: |
About the simplest thing we can do to
two
signals is to add them together:
>> out2 = sig1 + sig2; | |
Step 3: |
Listen to
out2
and look at its spectrogram.
Can you identify the two different signals in both the
audible and visual domains?
| |
Note: |
Both the A/D converter which digitized the input signal
and the D/A converter which converts the processed samples
back to an analog signal have limited range of values that
they can represent.
By keeping our input signal below 5 V
we keep it within the range of the A/D converter
and avoid "clipping" the signal.
However, when we add two signals together
or send then through systems having a gain greater than one,
we may create an output signal with values too large for
the D/A converter to convert.
If this happens you will hear distortion in the output signal.
To avoid this, you can use the
soundsc()
command instead of
sound().
This command automatically scales the signal value so that
it fits within the range of the D/A converter.
| |
Step 4: |
Another interesting thing we can do is
multiply
the two signals together.
Digitally, this is just as easy to do as adding them, but
this is very difficult to do in an analog circuit.
>> out3 = sig1 .* sig2;
Note the special Matlab construct ".*" denoting point
by point multiplication, as opposed to matrix multiplication.
| |
Step 5: |
Listen to out3 and look at its spectrogram. Can you identify either of the two signals in either the aural or visual domains? |
>> y = filter(b, a, x);
Choosing the values of the s and s is the art of filter design, which we'll look at in the next part. For now, we'll just try a few simple values for a and b.
| ||
Step 1: |
A
finite impulse response
(FIR) or non-recursive
filter has all the
(except
)
equal to zero, i.e. it is a weighted sum of input samples.
The simplest FIR filter is the
boxcar
filter
in which
all the
are equal to 1.
Define a length 5 boxcar filter:
>> a=1; | |
Step 2: |
Matlab has a function to compute and display the frequency response
of a filter:
>> freqz(b, a) Note that the frequency axis is labeled in terms of the Nyquist frequency, which is 1/2 the sampling rate. So for our sampling rate, 1 corresponds to 5 kHz.
Although it is a little distorted because of the logarithmic
scaling, this
is a close relative of
our old friend
.
Also note that the jumps in phase are caused by a change
in sign of the transfer function (the magnitude is always positive).
Taking this into account,
the phase is a
linear
function of frequency.
| |
Step 3: |
We can also look at the
unit-sample response
of the filter:
>> delta = [1 zeros(1,100)];
As you would expect, the unit-sample response is a rectangular pulse,
which supposedly looks like the side view of a boxcar.
| |
Step 4: |
Now let's try applying this filter to our signal:
>> out1 = filter(b, a, sig1); | |
Step 5: |
Listen to
out1
and look at its spectrogram.
>> sound(out1, Fs)
As you can tell from its frequency response plot,
this is a "sort-of" lowpass filter, though not a very good one.
Can you tell this by comparing the sound and spectrogram of the output
with the input?
What do the blue areas of the spectrogram correspond to?
| |
Step 6: |
Repeat steps 1 through 5 using a length 10 boxcar filter.
| |
Question 2: |
What is the relation between the length of the filter and its
frequency response?
| |
Step 7: |
An
infinite impulse response
(IIR) filter has an unit-sample response that doesn't go to zero
after a finite number of samples.
IIR filters are usually implemented
recursively,
i.e. with non-zero
coefficients
Define a first order recursive filter:
>> a=[1, -.9]; | |
Step 8: |
Using the same technique as above, look at its
unit-sample and frequency response.
Note that this is also a lowpass filter, with a more
conventional frequency response than the boxcar filter.
| |
Step 9: |
Apply this filter to the input signal.
Listen to the output and plot its spectrogram.
Can you tell by listening and looking that this is a lowpass filter?
| |
Step 10: |
An interesting thing happens if we change the sign of
:
>> a=[1 .9]; Look at the unit-sample and frequency response of this filter. Apply it to the input signal, listen to the output, and plot its spectrogram. What kind of filter is this? |
| ||
Step 1: |
The
Butterworth
filter is one of the classic filter designs.
It is characterized by having the "flattest" possible
passband.
Unfortunately, its performance in the stop band is decidedly mediocre.
Design a 5th order lowpass Butterworth filter having a cutoff frequency of 600 Hz with out 10 kHz sampling frequency:
>> [b,a] = butter(5, 600/5000); | |
Step 2: |
Print out the coefficients:
>> a,b | |
Step 3: |
Look at the unit-sample response and the frequency response.
Notice how much closer this is to an ideal low pass filter.
Also notice the scale on the y-axis.
For a better comparison with previous plots, try changing this scale:
>> subplot(2,1,1)
Also note that the phase is not linear.
| |
Step 4: |
Now apply the filter to our input signal
>> out1=filter(b, a, sig1);
and listen to the output.
| |
Step 5: |
We can also design FIR filters that are significantly better
than our boxcar filter:
>> a=1
Examine the unit-sample and frequency response of this filter
and apply it to the reference signal.
| |
Step 6: |
FIR filters really start to get interesting when we build very long ones.
Try the same cutoff frequency with 50 coefficients:
>> b=fir1(50,600/5000);
Note that we now have a filter of order 50.
How would you like to design and build an analog (RLC) filter
of this order?
| |
Step 7: |
Look at the unit-sample and frequency response of this filter.
What function does the unit-sample response remind you of?
Note that this filter has a much more ideal shape than any of
the others.
| |
Step 8: |
Finally, apply this filter to the reference signal.
Can you tell the difference in the sound or the spectrogram between
the effects of this filter and the length 5 filter?
| |
Step 9: |
If you like, you can
save your signals in your owlnet directory by dragging
them from the desktop to the "Homes on Long-eared" icon
under "My Computer".
| |
Step 10: |
When you are finished, remove your signals from the desktop by dragging them to the "Recycle Bin". |