Professional Documents
Culture Documents
I. Introduction
The Dirac delta function
The Dirac delta function (or δ distribution), also known as the unit impulse, is a
generalized function on the real numbers, whose value is zero everywhere except at zero,
and whose integral over the entire real line is equal to one.
The Dirac delta function delta dirac can be loosely thought of as a function on the real
line which is zero everywhere except at the origin, where it is infinite,
n=length(x);
F=0:(n-1)*fs/n;
Y=fft(x,n);
F0=(-n/2:n/2-1).*(fs/n);
Y0=fftshift(Y);
AY=abs(Y0);
subplot(2,1,2); plot(F0,AY,'LineWidth',1.5');
xlabel('Frequency (Hz)'); ylabel('Amplitude');
title('Frequency Domain Plot of Audio Signal');
filename='speech.wav';
audiowrite(filename,x,fs);
%sound(x,fs,bits);
EXPLAIN: This MATLAB code records audio from the computer's microphone, then
plots the waveform and frequency domain of the recorded audio signal. Here's the
breakdown:
1. clc; clear all;: Clears the command window and removes all variables from the
MATLAB workspace to start with a clean working environment.
2. fs=8000; Channels=1; bits=16;: Sets the recording parameters, including the
sampling frequency (fs), number of channels (Channels), and bits per sample
(bits).
3. r=audiorecorder(fs,bits,Channels);: Creates an audiorecorder object with the
specified parameters.
4. duration=5; disp('Recording started'); recordblocking(r,duration); disp('Recording
stopped');: Begins recording for 5 seconds and displays recording status messages.
5. x=getaudiodata(r);: Retrieves the recorded audio data from the audiorecorder
object and stores it in the variable x.
6. t=0:1/fs:(length(x)-1)/fs;: Generates the time vector t corresponding to the samples
in the audio data.
7. subplot(2,1,1); plot(t,x,'LineWidth',1.5); xlabel('time (sec)'); ylabel('Amplitude');
title('Time Domain Plot of the Recorded Signal');: Plots the waveform of the audio
signal in the time domain.
8. n=length(x); F=0:(n-1)*fs/n; Y=fft(x,n); F0=(-n/2:n/2-1).*(fs/n); Y0=fftshift(Y);
AY=abs(Y0); subplot(2,1,2); plot(F0,AY,'LineWidth',1.5'); xlabel('Frequency
(Hz)'); ylabel('Amplitude'); title('Frequency Domain Plot of Audio Signal');:
Performs the Fourier transform of the audio signal and plots the corresponding
frequency domain.
9. filename='speech.wav'; audiowrite(filename,x,fs);: Saves the recorded audio signal
to a WAV file named 'speech.wav'.
10. %sound(x,fs,bits);: This line is commented out (using %), otherwise it would play
back the recorded audio within MATLAB.
This code provides a simple way to record audio from a microphone and visualize both
the waveform and frequency domain of the recorded audio signal.
III. Results