Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

% - Matlab demonstration, first day of class

% Matlab 6.1

% Record 4 seconds of speech:


% default 8kHz sampling rate

y = audiorecorder; % creates a record object.


recordblocking(y,4); % records 4 seconds of speech

% note, other way of recording is to


% use wavrecord, previous version of matlab.

% 1. Get the array of signal values

s = getaudiodata(y);

% 2. Play back

sound(s);

% 3. play back in time reverse

sound(s(length(s):-1:1))

% 4. plot the signal

plot(s);

% 5. listen negative of signal

sound(-s);

% Q: why is it the same?


% A: just a uniform phase shift, we'll learn
% why in this course.

% 6. multiplied by a constant

sound(s/2)

% 7. square of the signal (make a little louder)

sound(3*s.^2)

% non-linear distortion

% 8. cube root of the signal (make a little software)

sound(cbrt(s)/3)
% 9. Spectral content of signal

freqz(s,[1],[],8000);

% 10. *Linear* frequency shift of signal,


% simple matlab routine that I wrote.

ss = freqshift(s,8000,500);

sound(ss);

freqz(ss,[1],[],8000);

% we'll see freqshift later in the course.

% 11. spectrogram of the signal

specgram(s,512,8000,[],512-32);

% 12. spectrogram of frequency shifted signal

specgram(ss,512,8000,[],512-32);

% 13. Design a simple band pass filter, passing only


% the components from 1k to 2k Hz.

filt = kaiserwinbp(2*pi*1/8,2*pi*1.01/8,2*pi*2/8,2*pi*2.1/8,0.001);

% kaiserwinbp designes a standard kaiswer window using the


% method discussed in the text.

sf = filter(filt,[1],s);

specgram(sf,512,8000,[],512-32);

sound(sf)

% 14. How about from .5k to 1kHz?

filt = kaiserwinbp(2*pi*.5/8,2*pi*.51/8,2*pi*1/8,2*pi*1.01/8,0.001);
sf = filter(filt,[1],s);
specgram(sf,512,8000,[],512-32);
sound(sf)

% 15. Make it twice as fast:

sound(s(1:2:length(s)));
% But there are problems with this, aliasing.

You might also like