Saturday, December 21, 2024

Plotting with MATLAB

Voice recording, playback and plotting. To record your voice, use the following commands:

audio = audiorecorder(Fs, nBits,
nChannels);

Here, Fs is the sampling rate in Hz. Valid values for Fs depend on the specific audio hardware installed. Typical values supported by most sound cards are 8000, 11,025, 22,050 and 44,100Hz—default value is 8000Hz.

- Advertisement -
DCB_Fig_15
Fig. 15: Difference between 8000Hz and 80Hz sampling rate

Nbits is bits per sample. Valid values for nBits depend on the operating system. For Windows, it is 8, 16, 24—default is 8.

nChannels is the number of channels: 1 (mono) or 2 (stereo)—default is 1.

- Advertisement -

For example,

[stextbox id=”grey”]audio = audiorecorder(8000, 8,1);
record(audio, 5); % 5 seconds for
recording.
test = getaudiodata(audio); % Store
data in double-precision array.
sound(test);
plot(test);[/stextbox]

As shown in Fig. 13, the plot is of recorded audio signal at the sampling rate of 8000Hz. Now, we will change the sampling rate to 80Hz, record and plot audio signal as shown in Fig. 14.

[stextbox id=”grey”]audio2 = audiorecorder(80, 8,1);
record(audio2, 5); % 5 seconds for
recording.
test2 = getaudiodata(audio2); % Store
data in double-precision array.
sound(test2);
plot(test2);[/stextbox]

Next, we plot both the audio signals of different sampling rates (8000Hz and 80Hz) on the same screen. The commands for the same are given below:

[stextbox id=”grey”]plot (test);
hold on
plot (test 2, ‘r’);[/stextbox]

The output plot is shown in Fig. 15.


The author is a B.Tech in electronics and communication from SRCEM, Gwalior

4 COMMENTS

SHARE YOUR THOUGHTS & COMMENTS

EFY Prime

Unique DIY Projects

Truly Innovative Electronics

Electronics News

Latest DIY Videos

Electronics Components

Electronics Jobs

Calculators For Electronics