Question 2

advertisement
CSE3451 Section E
Lab Assignment 2
Signal Sampling, Manipulation, and
Playback
By: Aysar Khalid (209728866)
Submitted on: September 30th, 2011
Introduction
In this lab we were learned how to convert analog signals into digital signals. The objective was
to import real signals, such as speech audio using a microphone, and to export it via an output
device such as headphones. Using MATLAB we plotted, displayed and analyzed these signals
digitally. Then we performed experimental manipulations to various characteristics of the
signal such as varying the frequency which in turn changes the pitch. We also performed
mathematical modifications to digital audio to produce echoing effects.
Lab Preparation
Question 1
If we were to call the half function on the samples of the signal (stored in a row vector), then
half would output every other element. Meaning there would be fewer samples in the
outputted vector than the original sample vector; to be precise there would be 4000 samples
per second. And since the sample rate is the same as the playback rate then this affect would
be the same on the playback rate which means the playback of the tone would be less clear and
would have more noise.
Hence, more sampling values in the vector give a higher quality playback. This can be shown
using the double function, which would increase the size of the sampling vector to double its
original length minus one (15999 samples per second) and it would add neighbouring averages
to each element. Therefore, using the double function would give a clearer and less noiseprevalent playback. Higher sampling rates also allow to accurately record higher frequencies of
sound. If the original sampled vector is a column vector this would not affect the use of the
functions as it has been tested and outputs correct results.
Question 2
The fliplr flips a given vector from left to right; for example:
If A is a row vector, A = [ 1 3 5 7 9 ] then fliplr(A) produces [ 9 7 5 3 1 ]
Note that fliplr is limited to only 1 and 2-dimensional vectors only. If fliplr is applied on a
sampled row vector then the playback will be played in reverse (good for hearing subliminal
messages?). If fliplr is applied on a sampled column vector then the output would not be any
different from the original vector.
The flipud flips a given vector from up to down; for example:
If A is a column vector, A = [ 1 3 5 7 9 ] then flipud(A) produces [ 9 7 5 3 1 ]
Note that flipud is limited to only 1 and 2-dimensional vectors only. If flipud is applied on a
sampled column vector then the playback will be played in reverse (good for hearing subliminal
messages?). If flipud is applied on a sampled row vector then the output would not be any
different from the original vector.
Question 3
Please see MATLAB folder for function, the following is the main algorithm;
lx = length(x);
n = zeros(1,lx*2+T);
n(1:lx) = x;
n(lx+T+1:end)= a.*x
Lab Experiment
Question 1
This question was skipped at the discretion of the Professor and TA.
Question 2
A file, ‘P_2_1.wav’, that represented a sampled signal was played in MATLAB by first loading it
in by using the wavread command and then sound to play it. It is crucial to note here that
although MATLAB attempts to scale the loaded sound file for playback our attempts in
autoscaling it using the saxis(‘auto’) command were unaccounted for simply because no such
command (or an alternative) existed most likely due to it being out-dated. When the signal is
played, the following is heard: Four five chickens and a coke and some dry wheat toast please.
It is important to note that when the sound is played its quality is lower, has some static in the
background and seems to be played at a lower volume than when played with other programs.
Question 3
In the first task, we created a 100-Hz sine wave with 0.6V amplitude and sampled the wave at
8000 Hz. We plotted the signal and played it- it sounded like a medium-low hum.
In the next task, we played the signal from the ‘P_2_1.wav’ file. Sampling at 8000 Hz, the sound
had amplitude of 0.25V and lasted 3 seconds.
In the final task, we recorded our own speech, sampled it and plotted it.
Question 4
MATLAB Function
Effect
Half
-
Speeds up the signal.
Size of file is halved.
Quality decreased
Double
-
Slows down the signal by almost quadruple
original. Original signal took 3 seconds,
modified signal takes 12 seconds.
Contains some echoing/repeated sounds
Fliplr
Flipud
-
Slower than original. Length of signal
took double the time it took original.
Some echoing/repeated sounds
-
No different from Fliplr output
No, the speech segment sound does not sound like it was produced by the same speaker as the
original. This is an unexpected phenomenon, but may be due to how MATLAB loads the signal.
It could be potentially loading it at a low sample rate because the original sound is much higher
in quality than the speech segment. Or it may be due to scaling.
Question 5
In the first task we generated an echo using a constant Alpha, 0.65. The effect of the echo with
a 0.25 second time delay seemed expected and minimal. When a non-constant attenuation
function was introduced things got more interested. As we varied values for A and τ- we
noticed that if we increased both of there values the echo would have a much higher volume
and sometimes it would get really high and get static. Keeping τ constant and increasing A,
made the echo increase its volume- which was expected since A was the amplitude of the
signal. Keeping A constant, and increasing τ, did not seem to do any changes to the echo, even
after analyzing a plot of the echo and comparing it with the original- τ’s variance does not seem
to have any effect.
When an oscillatory attenuation function was introduced keeping A constant, and increasing τ,
made the echo have more repetitive sounds but also increased the main speech signal’s
amplitude as well (not just the echo). Increasing A and keeping τ constant simply increased the
echo’s volume- as expected.
When T changes during the echo-generation process- this will cause a shift in the final signal.
Specifically, if T is increasing, then the time delay will increase causing the echo to shift to
rightward in the signal vector. Which means the echo will be delayed further. Conversely, if
the time delay is decreasing during the echo-generation process then the echo will be delayed
less.
Experimental Parameters and Methods
The following are all the functions used in the lab:
Function
Description
main
This is the main script that tests all of functions
Double3
This function performs the double command
Half
This function performs the half command
P2
Solution to problem 2 from 2.5
P4
Solution to problem 4 from 2.5 – sine wave
P4s
Solution to problem 4 from 2.5 – speech
P5
Solution to problem 5 from 2.5 – with alpha = 0.65
P31
Solution to problem 3 from 2.5 – sine wave
P52
Solution to problem 5 from 2.5 – with non-constant attenuation fn.
P54
Solution to problem 5 from 2.5 – with oscillatory attenuation fn.
Prelab1
Solution to prelab question 1
Ps32
Solution to problem 3 from 2.5 – ‘P_2_1.wav’ signal
Ps33
Solution to problem 3 from 2.5 – speech signal
Q3prelab
Solution to prelab question 3
The following are all the commands used in the lab:
Command
Description
Plot
Plots the columns of Y versus the index of each value when Y is a
real number.
Subplot
Create axes in tiled positions
Title
Adds title to current axe
Length
Length of vector
Zeros
Creates an array of all zeros
Exp
Exponential
xLabel, yLabel, zLabel
Label x-, y-, and z-axis
fprintf
Write data to text file
Conclusions
To wrap up, MATLAB was used extensively in this lab to load in speech and sound files and to
manipulate and modify them to create new signals. During the lab a number of difficulties
were overcome, MATLAB command saxis(‘auto’) was not found and no alternative was
available which allowed us to conclude that MATLAB automatically autoscales the sound files
with it loads it. The command to draw on top of plots was found to be annotate. All in all, the
lab objectives were completed and although some results were interesting and unexpected
such as the non-constant attenuation function in the last problem whereby τ was varied yet not
much difference was seen.
Download