In: Electrical Engineering
Write a matlab code to do following steps;
i) Record your voice by sampling frequency 22 kHz
ii) Down sample the voice by 2 listen to your voice
iii) Down sample the voice by 3 listen to your voice
Please explain the code clearly. Thank you.
The steps include:
(arec = audiorecorder(Fs, nbits, channels, id), for recording audio , where channels are 1 for mono and 2 for stereo)
Matlab code:
clc;
clear all;
close all;
% set the parameters
fs=22050; % sampling frequency
nbits=16; % no of bits used to represent each sample
device_id= getfield(getfield(audiodevinfo, 'input'), 'ID');
audiorec = audiorecorder(Fs, nbits, 1, dev_id); % Creating the audiorecorder object
record(audiorec); % Now, speak into microphone
stop(audiorec);
data = getaudiodata(audiorec);% extracting recorded data
sound(data, Fs); % reproducing audio data
%downsampling voice by 2
fs1=fs/2;
audiorec = audiorecorder(Fs1, nbits, 1, dev_id); % Creating the audiorecorder object
speechplayer = play(audiorec); % Now, listen to the recording
stop(speechplayer);
data = getaudiodata(audiorec);
sound(data, Fs1); % reproducing audio data
%downsampling voice by 3
fs2=fs/3;
audiorec = audiorecorder(Fs2, nbits, 1, dev_id); % Creating the audiorecorder object
speechplayer = play(audiorec); % Now, listen to the recording
stop(speechplayer);
data = getaudiodata(audiorec);
sound(data, Fs2); % reproducing audio data