reference answer only signal
Question I
Part (a)
1.SOURCE CODE LISTING for numbers 0 - 9:
In this program we are going to load the .wav files into MATLAB code and we can be able to play the required key tones from 0 to 9 by executing the code and listen through the system output devices.
In order to execute the program, the .wav files must be present in the current directory in order to load or play the dial tones.
The time domain plot for the required key tone (including two frequency components) will be observed where the axis will be time on x axis &
Amplitude on Y axis.
Later the frequency Domain plot (indicating the dual frequencies) will be observed using fourier transform
of the time domain of the key tones and with the sampling rate of 8000 Hz .
In this plot the Dual tone Multiple Frequencies is observed in the plot (DTMF Concept) as each keytone is comprised of two frequency
components, one low frequency & one high frequency components. i.e. the Dual frequencies can be viewed separately in the plot for each number from 0 - 9.
%% Program
% To enter the number manually and listen the tone.
function program_aa
fprintf('Type 1 = Auto Play \n');
fprintf('Type 2 = Manual Play\n');
Type = input('\n enter the type of Input : Type = ');
%% Automatic Input Type
if Type == 1
% loading the .wav files
dial0= 'dial0.wav';
dial1= 'dial1.wav';
dial2= 'dial2.wav';
dial3= 'dial3.wav';
dial4= 'dial4.wav';
dial5= 'dial5.wav';
dial6= 'dial6.wav';
dial7= 'dial7.wav';
dial8= 'dial8.wav';
dial9= 'dial9.wav';
% reading the loaded .wav files
keypad_0 = wavread(dial0);
keypad_1 = wavread(dial1);
keypad_2 = wavread(dial2);
keypad_3 = wavread(dial3);
keypad_4 = wavread(dial4);
keypad_5 = wavread(dial5);
keypad_6 = wavread(dial6);
keypad_7 = wavread(dial7);
keypad_8 = wavread(dial8);
keypad_9 = wavread(dial9);
% playing the .wav files using output sources
wavplay(keypad_0)
wavplay(keypad_1)
wavplay(keypad_2)
wavplay(keypad_3)
wavplay(keypad_4)
wavplay(keypad_5)
wavplay(keypad_6)
wavplay(keypad_7)
wavplay(keypad_8)
wavplay(keypad_9)
end
%% Manual Input Type
if Type == 2
N = input('enter the number of keypad : N = ');
fprintf('\n The Number Entered = %g\n',N);
Fs = 8000; % Sampling Rate is 8 kHz
%% To load and Play for number 0
if N == 0
dial0= 'dial0.wav';
keypad_0 = wavread(dial0);
wavplay(keypad_0,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_0)); % Next power of 2 from length of y
Y = fft(keypad_0,FFT)/length(keypad_0);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',941);
fprintf('\n The High frequency component in Hz = %g\n',1336);
fprintf('\n The Fourier transform Max value = %g\n',norm(y));
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y) ;
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_0);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 1
if N == 1
dial1= 'dial1.wav';
keypad_1 = wavread(dial1);
wavplay(keypad_1,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_1)); % Next power of 2 from length of y
Y = fft(keypad_1,FFT)/length(keypad_1);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',697);
fprintf('\n The High frequency component in Hz = %g\n',1209);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_1);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 2
if N == 2
dial2= 'dial2.wav';
keypad_2 = wavread(dial2);
wavplay(keypad_2,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_2)); % Next power of 2 from length of y
Y = fft(keypad_2,FFT)/length(keypad_2);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',697);
fprintf('\n The High frequency component in Hz = %g\n',1336);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_2);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 3
if N == 3
dial3= 'dial3.wav';
keypad_3 = wavread(dial3);
wavplay(keypad_3,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_3)); % Next power of 2 from length of y
Y = fft(keypad_3,FFT)/length(keypad_3);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',697);
fprintf('\n The High frequency component in Hz = %g\n',1497);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_3);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 4
if N == 4
dial4= 'dial4.wav';
keypad_4 = wavread(dial4);
wavplay(keypad_4,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_4)); % Next power of 2 from length of y
Y = fft(keypad_4,FFT)/length(keypad_4);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',770);
fprintf('\n The High frequency component in Hz = %g\n',1209);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_4);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 5
if N == 5
dial5= 'dial5.wav';
keypad_5 = wavread(dial5);
wavplay(keypad_5,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_5)); % Next power of 2 from length of y
Y = fft(keypad_5,FFT)/length(keypad_5);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',770);
fprintf('\n The High frequency component in Hz = %g\n',1336);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_5);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 6
if N == 6
dial6= 'dial6.wav';
keypad_6 = wavread(dial6);
wavplay(keypad_6,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_6)); % Next power of 2 from length of y
Y = fft(keypad_6,FFT)/length(keypad_6);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',770);
fprintf('\n The High frequency component in Hz = %g\n',1497);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_6);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 7
if N == 7
dial7= 'dial7.wav';
keypad_7 = wavread(dial7);
wavplay(keypad_7,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_7)); % Next power of 2 from length of y
Y = fft(keypad_7,FFT)/length(keypad_7);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',852);
fprintf('\n The High frequency component in Hz = %g\n',1209);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_7);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 8
if N == 8
dial8= 'dial8.wav';
keypad_8 = wavread(dial8);
wavplay(keypad_8,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_8)); % Next power of 2 from length of y
Y = fft(keypad_8,FFT)/length(keypad_8);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',852);
fprintf('\n The High frequency component in Hz = %g\n',1336);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_8);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 9
if N == 9
dial9= 'dial9.wav';
keypad_9 = wavread(dial9);
wavplay(keypad_9,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_9)); % Next power of 2 from length of y
Y = fft(keypad_9,FFT)/length(keypad_9);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',852);
fprintf('\n The High frequency component in Hz = %g\n',1497);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_9);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for star key
if N == 10
dialstar= 'dialstar.wav';
keypad_star = wavread(dialstar);
wavplay(keypad_star,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_star)); % Next power of 2 from length of y
Y = fft(keypad_star,FFT)/length(keypad_star);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',941);
fprintf('\n The High frequency component in Hz = %g\n',1209);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_star);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for Hash key
if N == 11
dialhash= 'dialhash.wav';
keypad_hash = wavread(dialhash);
wavplay(keypad_hash,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_hash)); % Next power of 2 from length of y
Y = fft(keypad_hash,FFT)/length(keypad_hash);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',941);
fprintf('\n The High frequency component in Hz = %g\n',1497);
% Plot Fourier Transform magnitude spectrum (Frequency Domain).
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_hash);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
end
% end program
2. Two Representative Waveforms in Time Domain :
The Two representatives Wave forms observed after execution of the above Code will be considered for Dial 0 and Dial 1 respectively.
Time Domain Wave Forms for DIAL0:
a) Time domain plot (indicating presence of two frequency components)
b) Time domain plot (by zooming into the above graph)
Time Domain Wave Forms for DIAL1:
a) Time domain plot (indicating presence of two frequency components in time domain)
b) Time domain plot (by zooming into the above graph)
3. Two Representative Waveforms in Frequency Domain :
Frequency Domain Waveforms for DIAL0:
a) Frequency domain plot for dial0 (indicating 941 Hz & 1336 Hz)
b) Low frequency Component plot (by zooming into the above graph indicating 941 Hz)
c) High frequency Component plot (by zooming into the above graph indicating 1336 Hz)
Frequency Domain Waveforms for DIAL1:
a) Frequency domain plot for dial1 (indicating 697 Hz & 1209 Hz)
b) Low frequency Component plot (by zooming into the above graph indicating 697 Hz)
c) High frequency Component plot (by zooming into the above graph indicating 1209 Hz)
Part (b)
Standard DTMF Frequencies:
The Standard DTMF dial tone frequency table indicating Low Frequency Components And High Frequency Components is given below.
Low Frequency Component(Hz)
High Frequency Component
(Hz)
Dial0 941 1336
Dial1 697 1209
Dial2 697 1336
Dial3 697 1477
Dial4 770 1209
Dial5 770 1336
Dial6 770 1477
Dial7 852 1209
Dial8 852 1336
Dial9 852 1477
Measured DTMF Frequencies:
The Measured frequency components of the numbers 0 - 9 derived by fourier Transform of the dial tones and that are observed from the plots are
given below.
Low Frequency Component
(Hz)
High Frequency Component
(Hz)
Dial0 941 1336
Dial1 697 1209
Dial2 697 1336
Dial3 697 1477
Dial4 770 1209
Dial5 770 1336
Dial6 770 1477
Dial7 852 1209
Dial8 852 1336
Dial9 852 1477
The following explains the Fourier transform performed in the programme for number 0 (in detail)
FFT = 2^nextpow2(length(keypad_0));
% Here, initially the length of the signal is considered by 'Length(Keypad_0)' command then the
smallest power of two that is greater than or equal to the absolute value of length(keypad_0)
will be obtain using 'nextpow2' command and it is given in the power for 2. This result is stored
in a variable called FFT.
Y = fft(keypad_0,FFT)/length(keypad_0);
% Here,the fourier Transform is Performed by considering the 'fft' Command as permitted and the
parameters for transformation are considered to be the Time domain output of the Dial0 and the
variable FFT. This obtained output is divided by the length of the Signal and the final output is
stored in variable Y.
f = 8000/2*linspace(0,1,FFT/2);
% Here the separately spaced vector for the previously obtained 'FFT' output is obtained by using
'linspace' command and it is multiplied with half the Sampling rate i.e 8 kHz = 8000 Hz and the
obtained output is a frequency domain output which is stored in a variable 'f'.
plot(f,2*abs(Y(1:FFT/2)))
% To plot the obtained frequency domain output, the Absolute value of the FFT is fourier
transformed 'FFT' is considered in order to maintain the matrix dimensions for plotting the exact
plot.
Hence the plot obtained consists of the frequency domain output of the time domain function
dial0.
QUESTION-1 Part-B
% CODE LISTING:
% In this program we are going to load the .wav files into matlab code and
% we can be able to play the required key tones from 0 to 9 including '*' and '#' keys( 10 & 11
numbers respectively)
% by executing the code and listen through the system output devices.
% In order to execute the program, the .wav files must be present in the
% current directory in order to load or play the dial tones.
% Later the time domain plot is observed where the axis will be time or samples on x axis &
Amplitude on Y axis.
% Later that the frequency Domain plot is observed using fourier transform
% of the keytones and with the sampling rate of 8000 Hz . In this plot the Dual tone Multiple
Frequencies are observed in the plot (DTMF Concept)
% i.e. the Dual frequencies can be viewed separately in the plot for each number from 0 - 9
including '*' & '#' keys
%% Program
% To enter the number manually and listen the tone.
function program_part_b
N=input('enter the number of keypad : N = ');
Fs = 8000; % Sampling Rate is 8 kHz
%% To load and Play for number 0
if N == 0
dial0= 'dial0.wav';
keypad_0 = wavread(dial0);
wavplay(keypad_0,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_0)); % Next power of 2 from length of y
Y = fft(keypad_0,FFT)/length(keypad_0);
f = 8000/2*linspace(0,1,FFT/2);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,2*abs(Y(1:FFT/2)))
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_0);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 1
if N == 1
dial1= 'dial1.wav';
keypad_1 = wavread(dial1);
wavplay(keypad_1,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_1)); % Next power of 2 from length of y
Y = fft(keypad_1,FFT)/length(keypad_1);
f = 8000/2*linspace(0,1,FFT/2);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,2*abs(Y(1:FFT/2)))
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_1);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 2
if N == 2
dial2= 'dial2.wav';
keypad_2 = wavread(dial2);
wavplay(keypad_2,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_2)); % Next power of 2 from length of y
Y = fft(keypad_2,FFT)/length(keypad_2);
f = 8000/2*linspace(0,1,FFT/2);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,2*abs(Y(1:FFT/2)))
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_2);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 3
if N == 3
dial3= 'dial3.wav';
keypad_3 = wavread(dial3);
wavplay(keypad_3,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_3)); % Next power of 2 from length of y
Y = fft(keypad_3,FFT)/length(keypad_3);
f = 8000/2*linspace(0,1,FFT/2);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,2*abs(Y(1:FFT/2)))
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_3);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 4
if N == 4
dial4= 'dial4.wav';
keypad_4 = wavread(dial4);
wavplay(keypad_4,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_4)); % Next power of 2 from length of y
Y = fft(keypad_4,FFT)/length(keypad_4);
f = 8000/2*linspace(0,1,FFT/2);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,2*abs(Y(1:FFT/2)))
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_4);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 5
if N == 5
dial5= 'dial5.wav';
keypad_5 = wavread(dial5);
wavplay(keypad_5,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_5)); % Next power of 2 from length of y
Y = fft(keypad_5,FFT)/length(keypad_5);
f = 8000/2*linspace(0,1,FFT/2);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,2*abs(Y(1:FFT/2)))
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_5);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 6
if N == 6
dial6= 'dial6.wav';
keypad_6 = wavread(dial6);
wavplay(keypad_6,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_6)); % Next power of 2 from length of y
Y = fft(keypad_6,FFT)/length(keypad_6);
f = 8000/2*linspace(0,1,FFT/2);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,2*abs(Y(1:FFT/2)))
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_6);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 7
if N == 7
dial7= 'dial7.wav';
keypad_7 = wavread(dial7);
wavplay(keypad_7,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_7)); % Next power of 2 from length of y
Y = fft(keypad_7,FFT)/length(keypad_7);
f = 8000/2*linspace(0,1,FFT/2);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,2*abs(Y(1:FFT/2)))
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_7);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 8
if N == 8
dial8= 'dial8.wav';
keypad_8 = wavread(dial8);
wavplay(keypad_8,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_8)); % Next power of 2 from length of y
Y = fft(keypad_8,FFT)/length(keypad_8);
f = 8000/2*linspace(0,1,FFT/2);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,2*abs(Y(1:FFT/2)))
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_8);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 9
if N == 9
dial9= 'dial9.wav';
keypad_9 = wavread(dial9);
wavplay(keypad_9,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_9)); % Next power of 2 from length of y
Y = fft(keypad_9,FFT)/length(keypad_9);
f = 8000/2*linspace(0,1,FFT/2);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,2*abs(Y(1:FFT/2)))
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_9);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for star key
if N == 10
dialstar= 'dialstar.wav';
keypad_star = wavread(dialstar);
wavplay(keypad_star,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_star)); % Next power of 2 from length of y
Y = fft(keypad_star,FFT)/length(keypad_star);
f = 8000/2*linspace(0,1,FFT/2);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,2*abs(Y(1:FFT/2)))
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_star);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for Hash key
if N == 11
dialhash= 'dialhash.wav';
keypad_hash = wavread(dialhash);
wavplay(keypad_hash,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_hash)); % Next power of 2 from length of y
Y = fft(keypad_hash,FFT)/length(keypad_hash);
f = 8000/2*linspace(0,1,FFT/2);
% Plot Fourier Transform magnitude spectrum (Frequency Domain).
subplot (2,1,1)
plot(f,2*abs(Y(1:FFT/2)))
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_hash);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
save keypad_hash keypad_hash
end
end
% end program
Question-2
%% Question II
%% Part a
% SOURCE CODE LISTING
% In this program we are going to load the .wav files into matlab code and
% play them through the system output devices and through Matlab code.
% In order to execute the program, the .wav files must be present in the
% current directory in order to load or play the dial tones.
% In this program there will be three modes of execution , one is testing
% mode using dial0123.wav , second is the determining mode using key
% sequence, the third one is the comparision of the above two modes.
% In Test mode, the dial0123 tone is loaded and played , then the
% number of keytones present in the sequence are observed and
% plotted.Then fourier transform is performed in order to convert the signal to
% frequency domain and the frequencies of the signal is determined.
% These frequencies contain the Low frequency component & High
% frequency component of all the keytones. All these frequencies are
% used for finding out the correct keytones used in dial0123.wav and
% also in order to dertermine the sequence. the determination of the
% sequence wil be done using automatic mode.
% basing on the test mode , the number of keytones available in the signal & their
% frequencies are deterined. The frequencies of the signals generated by the sequence should
match according to that of the test mode.
% So After the execution of the Test mode the frequencies of the
% keytones are found to be the standaard DTMF keytones for dial0 dial1
% dial2 dial3. The keytones dial0 dial1 dial2 dial3 sequence is
% directly executed in automatic mode.
% This mode must be executed after the Test and Automatic modes in order to enter the
variables in worksace.
% In the comparision mode , both the frequencies whic are generated in
% test mode and automatic mode are compared. As mentioned the length of
% the signal is independent and the waveform must not rely, the both
% the signals have same frequencies but with individual standard
% lengths.
%% Program
fprintf('\n\nPress 1 for Test Mode using dial0123 \n');
fprintf('Press 2 for Automatic Mode, playing tones to determine the sequence \n');
fprintf('Press 3 for comparision between waveform from dial0123 with generated waveform from
sequence\n\n\n');
N=input('enter the mode : N = ');
Fs = 8000; % Sampling Rate is 8 kHz
T = 1/Fs; % Samling time
%% TEST MODE
if N == 1
dial0l23= 'dial0123.wav';
keypad_0123 = wavread(dial0l23);
wavplay(keypad_0123,Fs)
% Fourier Transformation
L = length(keypad_0123);
T = 1/Fs;
t = (0:L-1)*T;
FFT = 2^nextpow2(L);
Y = fft(keypad_0123,FFT)/L;
f = Fs/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
%plotting
figure(1)
plot(f,y)
axis([0 2000 0 0.3])
fprintf('\n The tone played = dial 0123 \n');
fprintf('\n The frequencies generated by the signal are \n 697Hz, \n 941Hz ,\n 1209Hz, \n 1336Hz,
\n 1477Hz \n');
fprintf('\n The frequencies generated by the signal are signal are similar to the standard DTMF
drequencies for numbers 0 1 2 3\n')
end
%% AUTOMATIC MODE
if N == 2
%To load and Play for number 0
dial0= 'dial0.wav';
keypad_0 = wavread(dial0);
wavplay(keypad_0,Fs)
% Fourier Transformation
L0 = length(keypad_0);
t0 = (0:L0-1)*T;
FFT0 = 2^nextpow2(L0);
Y0 = fft(keypad_0,FFT0)/L0;
f0 = Fs/2*linspace(0,1,FFT0/2);
y0 = 2*abs(Y0(1:FFT0/2));
%To load and Play for number 1
dial1= 'dial1.wav';
keypad_1 = wavread(dial1);
wavplay(keypad_1,Fs)
% Fourier Transformation
L1 = length(keypad_1);
t1 = (0:L1-1)*T;
FFT1 = 2^nextpow2(L1);
Y1 = fft(keypad_1,FFT1)/L1;
f1 = Fs/2*linspace(0,1,FFT1/2);
y1 = 2*abs(Y1(1:FFT1/2));
%To load and Play for number 2
dial2= 'dial2.wav';
keypad_2 = wavread(dial2);
wavplay(keypad_2,Fs)
% Fourier Transformation
L2 = length(keypad_2);
t2 = (0:L2-1)*T;
FFT2 = 2^nextpow2(L2);
Y2 = fft(keypad_2,FFT2)/L2;
f2 = Fs/2*linspace(0,1,FFT2/2);
y2 = 2*abs(Y2(1:FFT2/2));
% To load and Play for number 3
dial3= 'dial3.wav';
keypad_3 = wavread(dial3);
wavplay(keypad_3,Fs)
% Fourier Transformation
L3 = length(keypad_3);
t3 = (0:L3-1)*T;
FFT3 = 2^nextpow2(L3);
Y3 = fft(keypad_3,FFT3)/L3;
f3 = Fs/2*linspace(0,1,FFT3/2);
y3 = 2*abs(Y3(1:FFT3/2));
%plotting frequency
figure(5)
plot(f0,y0,'b',f1,y1,'g',f2,y2,'r',f3,y3,'m')
axis([0 2000 0 0.3])
fprintf('\n The tones played = dial 0 dial1 dial2 dial3 \n');
fprintf('\n The frequencies observed from the sequence are \n 697Hz, \n 941Hz ,\n 1209Hz, \n
1336Hz, \n 1477Hz \n');
end
%% COMPARISION MODE
if N == 3
subplot(2,1,1)
plot(f,y)
axis([0 2000 0 0.3])
subplot(2,1,2)
plot(f0,y0,'b',f1,y1,'g',f2,y2,'r',f3,y3,'m')
axis([0 2000 0 0.3])
fprintf('\n The frequencies are matching \n');
end
% end program
Part-B
%% Question II
% Part b
% In this program we are going to load the .wav files into matlab code and
% play all the tones continuously or automatically through the system output devices and through
Matlab code.
% In order to execute the program, the .wav files must be present in the
% current directory in order to load or play the dial tones.
% In this program, there are two modes where in the mode 1, the
% dial<u><d><c>.wav file will be played where the value of <d> is the last
% digit of the student number and <c> is the Cean file with out any noise content in the signal.
% After the .wav file is played, the fourier transform is performed and the
% frequencies present in the signal are observed. Basing on the frequencies
% and its amplitudes, and also by observing the time domain wave form of the .wav file played,
% the sequence of the digits can be determined.
% In the second mode the individual .wav files for all the numbers will be
% present and by equating the time domain waveforms correspondingly with that of the
% mode 1 waveforms, and also the frequency domain waveforms, the sequence
% of the numbers played can be easily determined.
%% Program
fprintf('Type 1 = playing the sequence determined using last digit of student code \n');
fprintf('Type 2 = determinig the same sequence using the previous question\n');
Type = input('\n enter the type of Input : Type = ');
% Initializing the sampling frequency
Fs = 8000 ; %The value for sampling frequency 'Fs' is given 8 kHz (samples per second)
%% Sequence to be played basing on the last digit of student code is
if Type==1
% loading the .wav files
dialtone = 'dialu0c.wav';
% reading the loaded .wav files
keypad_tone = wavread(dialtone);
% playing the .wav files using output sources
wavplay(keypad_tone,Fs)
% Fourier Transformation
L = length(keypad_tone);
T = 1/Fs;
t = (0:L-1)*T;
FFT = 2^nextpow2(L);
Y = fft(keypad_tone,FFT)/L;
f = Fs/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
%plotting
figure(1)
plot(f,y)
axis([0 2000 0 0.105])
figure(2)
plot(keypad_tone)
fprintf('From the played .wav file, the sequence of frequencies observed are = \n');
fprintf('From the played .wav file, the sequence of numbers played = \n');
end
%% Deterining the sequence by verifying the above sequence using previous question.
if Type==2
N = input('enter the number of keypad : N = ');
fprintf('\n The Number Entered = %g\n',N);
Fs = 8000; % Sampling Rate is 8 kHz
%% To load and Play for number 0
if N == 0
dial0= 'dial0.wav';
keypad_0 = wavread(dial0);
wavplay(keypad_0,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_0)); % Next power of 2 from length of y
Y = fft(keypad_0,FFT)/length(keypad_0);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',941);
fprintf('\n The High frequency component in Hz = %g\n',1336);
fprintf('\n The Fourier transform Max value = %g\n',norm(y));
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y) ;
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_0);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 1
if N == 1
dial1= 'dial1.wav';
keypad_1 = wavread(dial1);
wavplay(keypad_1,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_1)); % Next power of 2 from length of y
Y = fft(keypad_1,FFT)/length(keypad_1);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',697);
fprintf('\n The High frequency component in Hz = %g\n',1209);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_1);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 2
if N == 2
dial2= 'dial2.wav';
keypad_2 = wavread(dial2);
wavplay(keypad_2,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_2)); % Next power of 2 from length of y
Y = fft(keypad_2,FFT)/length(keypad_2);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',697);
fprintf('\n The High frequency component in Hz = %g\n',1336);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_2);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 3
if N == 3
dial3= 'dial3.wav';
keypad_3 = wavread(dial3);
wavplay(keypad_3,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_3)); % Next power of 2 from length of y
Y = fft(keypad_3,FFT)/length(keypad_3);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',697);
fprintf('\n The High frequency component in Hz = %g\n',1497);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_3);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 4
if N == 4
dial4= 'dial4.wav';
keypad_4 = wavread(dial4);
wavplay(keypad_4,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_4)); % Next power of 2 from length of y
Y = fft(keypad_4,FFT)/length(keypad_4);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',770);
fprintf('\n The High frequency component in Hz = %g\n',1209);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_4);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 5
if N == 5
dial5= 'dial5.wav';
keypad_5 = wavread(dial5);
wavplay(keypad_5,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_5)); % Next power of 2 from length of y
Y = fft(keypad_5,FFT)/length(keypad_5);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',770);
fprintf('\n The High frequency component in Hz = %g\n',1336);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_5);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 6
if N == 6
dial6= 'dial6.wav';
keypad_6 = wavread(dial6);
wavplay(keypad_6,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_6)); % Next power of 2 from length of y
Y = fft(keypad_6,FFT)/length(keypad_6);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',770);
fprintf('\n The High frequency component in Hz = %g\n',1497);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_6);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 7
if N == 7
dial7= 'dial7.wav';
keypad_7 = wavread(dial7);
wavplay(keypad_7,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_7)); % Next power of 2 from length of y
Y = fft(keypad_7,FFT)/length(keypad_7);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',852);
fprintf('\n The High frequency component in Hz = %g\n',1209);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_7);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 8
if N == 8
dial8= 'dial8.wav';
keypad_8 = wavread(dial8);
wavplay(keypad_8,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_8)); % Next power of 2 from length of y
Y = fft(keypad_8,FFT)/length(keypad_8);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',852);
fprintf('\n The High frequency component in Hz = %g\n',1336);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_8);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 9
if N == 9
dial9= 'dial9.wav';
keypad_9 = wavread(dial9);
wavplay(keypad_9,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_9)); % Next power of 2 from length of y
Y = fft(keypad_9,FFT)/length(keypad_9);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',852);
fprintf('\n The High frequency component in Hz = %g\n',1497);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_9);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for star key
if N == 10
dialstar= 'dialstar.wav';
keypad_star = wavread(dialstar);
wavplay(keypad_star,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_star)); % Next power of 2 from length of y
Y = fft(keypad_star,FFT)/length(keypad_star);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',941);
fprintf('\n The High frequency component in Hz = %g\n',1209);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_star);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for Hash key
if N == 11
dialhash= 'dialhash.wav';
keypad_hash = wavread(dialhash);
wavplay(keypad_hash,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_hash)); % Next power of 2 from length of y
Y = fft(keypad_hash,FFT)/length(keypad_hash);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',941);
fprintf('\n The High frequency component in Hz = %g\n',1497);
% Plot Fourier Transform magnitude spectrum (Frequency Domain).
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_hash);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
fprintf('From the played .wav file, the sequence of frequencies observed are = \n');
fprintf('From the played .wav file, the sequence of numbers played = \n');
end
Question-3
%% Question III
% In this program we are going to load the .wav files into matlab code and
% play all the tones continuously or automatically through the system output devices and through
Matlab code.
% In order to execute the program, the .wav files must be present in the
% current directory in order to load or play the dial tones.
% In this program, there are two modes where in the mode 1, the
% dial<u><d><n>.wav file will be played where the value of <d> is the Second last
% digit of the student number and <n> will be the noise corrupted files.
% After the .wav file is played, the fourier transform is performed and the
% frequencies present in the signal are observed. Basing on the frequencies
% and its amplitudes, and also by observing the time domain wave form of the .wav file played,
% the sequence of the digits can be determined.
% In the second mode the individual .wav files for all the numbers will be
% present and by equating the time domain waveforms correspondingly with that of the
% mode 1 waveforms, and also the frequency domain waveforms, the sequence
% of the numbers played can be easily determined.
%% Program
fprintf('Type 1 = playing the sequence determined using last digit of student code \n');
fprintf('Type 2 = determinig the same sequence using the previous question\n');
Type = input('\n enter the type of Input : Type = ');
% Initializing the sampling frequency
Fs = 8000 ; %The value for sampling frequency 'Fs' is given 8 kHz (samples per second)
%% Sequence to be played basing on the last digit of student code is
if Type==1
% loading the .wav files
dialtone = 'dialu0n.wav';
% reading the loaded .wav files
keypad_tone = wavread(dialtone);
% playing the .wav files using output sources
wavplay(keypad_tone,Fs)
% Fourier Transformation
L = length(keypad_tone);
T = 1/Fs;
t = (0:L-1)*T;
FFT = 2^nextpow2(L);
Y = fft(keypad_tone,FFT)/L;
f = Fs/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
%plotting
figure(1)
plot(f,y)
axis([0 2000 0 0.105])
figure(2)
plot(keypad_tone)
fprintf('From the played .wav file, the sequence of frequencies observed are = \n');
fprintf('From the played .wav file, the sequence of numbers played = \n');
end
%% Deterining the sequence by verifying the above sequence using previous question.
if Type==2
N = input('enter the number of keypad : N = ');
fprintf('\n The Number Entered = %g\n',N);
Fs = 8000; % Sampling Rate is 8 kHz
%% To load and Play for number 0
if N == 0
dial0= 'dial0.wav';
keypad_0 = wavread(dial0);
wavplay(keypad_0,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_0)); % Next power of 2 from length of y
Y = fft(keypad_0,FFT)/length(keypad_0);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',941);
fprintf('\n The High frequency component in Hz = %g\n',1336);
fprintf('\n The Fourier transform Max value = %g\n',norm(y));
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y) ;
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_0);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 1
if N == 1
dial1= 'dial1.wav';
keypad_1 = wavread(dial1);
wavplay(keypad_1,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_1)); % Next power of 2 from length of y
Y = fft(keypad_1,FFT)/length(keypad_1);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',697);
fprintf('\n The High frequency component in Hz = %g\n',1209);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_1);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 2
if N == 2
dial2= 'dial2.wav';
keypad_2 = wavread(dial2);
wavplay(keypad_2,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_2)); % Next power of 2 from length of y
Y = fft(keypad_2,FFT)/length(keypad_2);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',697);
fprintf('\n The High frequency component in Hz = %g\n',1336);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_2);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 3
if N == 3
dial3= 'dial3.wav';
keypad_3 = wavread(dial3);
wavplay(keypad_3,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_3)); % Next power of 2 from length of y
Y = fft(keypad_3,FFT)/length(keypad_3);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',697);
fprintf('\n The High frequency component in Hz = %g\n',1497);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_3);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 4
if N == 4
dial4= 'dial4.wav';
keypad_4 = wavread(dial4);
wavplay(keypad_4,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_4)); % Next power of 2 from length of y
Y = fft(keypad_4,FFT)/length(keypad_4);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',770);
fprintf('\n The High frequency component in Hz = %g\n',1209);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_4);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 5
if N == 5
dial5= 'dial5.wav';
keypad_5 = wavread(dial5);
wavplay(keypad_5,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_5)); % Next power of 2 from length of y
Y = fft(keypad_5,FFT)/length(keypad_5);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',770);
fprintf('\n The High frequency component in Hz = %g\n',1336);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_5);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 6
if N == 6
dial6= 'dial6.wav';
keypad_6 = wavread(dial6);
wavplay(keypad_6,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_6)); % Next power of 2 from length of y
Y = fft(keypad_6,FFT)/length(keypad_6);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',770);
fprintf('\n The High frequency component in Hz = %g\n',1497);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_6);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 7
if N == 7
dial7= 'dial7.wav';
keypad_7 = wavread(dial7);
wavplay(keypad_7,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_7)); % Next power of 2 from length of y
Y = fft(keypad_7,FFT)/length(keypad_7);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',852);
fprintf('\n The High frequency component in Hz = %g\n',1209);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_7);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 8
if N == 8
dial8= 'dial8.wav';
keypad_8 = wavread(dial8);
wavplay(keypad_8,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_8)); % Next power of 2 from length of y
Y = fft(keypad_8,FFT)/length(keypad_8);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',852);
fprintf('\n The High frequency component in Hz = %g\n',1336);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_8);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for number 9
if N == 9
dial9= 'dial9.wav';
keypad_9 = wavread(dial9);
wavplay(keypad_9,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_9)); % Next power of 2 from length of y
Y = fft(keypad_9,FFT)/length(keypad_9);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',852);
fprintf('\n The High frequency component in Hz = %g\n',1497);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_9);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for star key
if N == 10
dialstar= 'dialstar.wav';
keypad_star = wavread(dialstar);
wavplay(keypad_star,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_star)); % Next power of 2 from length of y
Y = fft(keypad_star,FFT)/length(keypad_star);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',941);
fprintf('\n The High frequency component in Hz = %g\n',1209);
% Plot Fourier Transform magnitude spectrum.(Frequency Domain)
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_star);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
%% To load and Play for Hash key
if N == 11
dialhash= 'dialhash.wav';
keypad_hash = wavread(dialhash);
wavplay(keypad_hash,Fs)
% Fourier Transformation
FFT = 2^nextpow2(length(keypad_hash)); % Next power of 2 from length of y
Y = fft(keypad_hash,FFT)/length(keypad_hash);
f = 8000/2*linspace(0,1,FFT/2);
y = 2*abs(Y(1:FFT/2));
fprintf('\n The Low frequency component in Hz = %g\n',941);
fprintf('\n The High frequency component in Hz = %g\n',1497);
% Plot Fourier Transform magnitude spectrum (Frequency Domain).
subplot (2,1,1)
plot(f,y)
title('Fourier Transform magnitude spectrum')
xlabel('Frequency (Hz)')
ylabel('amplitude')
grid
% plotting Time domain waveform
subplot (2,1,2)
plot(keypad_hash);
title('Time domain Wave Form')
xlabel('Time / Samples')
ylabel('amplitude')
grid
end
fprintf('From the played .wav file, the sequence of frequencies observed are = \n');
fprintf('From the played .wav file, the sequence of numbers played = \n');
end
From the played .wav file, the sequence of numbers played =
Type 1 = playing the sequence determined using last digit of student code
Type 2 = determinig the same sequence using the previous question
enter the type of Input : Type = 1
From the played .wav file, the sequence of frequencies observed are =
From the played .wav file, the sequence of numbers played =
Type 1 = playing the sequence determined using last digit of student code
Type 2 = determinig the same sequence using the previous question
enter the type of Input : Type = 1
From the played .wav file, the sequence of frequencies observed are =
From the played .wav file, the sequence of numbers played =
QUESTION-4
%% Question IV
% In this program we are going to load the .wav files into matlab code and
% play all the tones continuously or automatically through the system output devices and through
Matlab code.
% In order to execute the program, the .wav files must be present in the
% current directory in order to load or play the dial tones.
%
%% Program
clear all;
%% initalzng the dialtone
dialu0c = 'dialu0c.wav';
keytone_dialu0c = wavread(dialu0c);
wavplay(keytone_dialu0c)
%% Sampling value & Time Vector
Fs = 8000;
alp_vct = 0:0.01:1;
%% Initializiing Parameters
X = length(keytone_dialu0c);
V = randn(size(X));
PS = sum(X.^2);
PV = sum(V.^2);
a=1;
%% SNR
if a <= length(alp_vct)
Y = X + alp_vct(a) * V;
SNR = 10 * log10(PS / ((alp_vct(a))^2*PV));
Dial_Keys = '';
Keys = 0;
numberTone = length(X)/(Fs/5);
%% Fourier Transformation
% For Iteration 1
itr=1;
if itr<= numberTone
Frame = X(((itr-1)*Fs/5+1):itr*Fs/5);
L = length(Frame);
Frame = Frame(1:L/2);
L = L/2;
FFT = 2^nextpow2(L);
f = Fs/2*linspace(0,1,FFT/2+1);
y = abs(fft(Frame, FFT));
Y = Y(1:round(length(f)/2));
[x1, i1] = max(y);
Y(i1) = 0;
[x2, i2] = max(y);
err = 1;
if i1 > i2
t = i1;
i1 = i2;
i2 = t;
end
%% For Errors
if err == 1
number = '*';
cntr=1;
if cntr<= 2
[tSS_freqnbits] = wavread(Wave2(cntr,:));
tS = tS(1:L);
Y1 = abs(fft(tS, FFT));
Y1 = Y1(1:round(length(f)/2));
[y1, j1] = max(Y1);
Y1(j1) = 0;
[y2, j2] = max(Y1);
if j1 > j2
t = j1;
j1 = j2;
j2 = t;
end
if i1 == j1
if i2 == j2
err = 0;
Keys = Keys + 1;
end
end
cntr=cntr+1;
end
if err == 1
number = '*';
elseif cntr==1
number = '#';
elseif cntr==2
number = '0';
end
end
itr=itr+1;
Dial_Key = strcat(Dial_Keys, number);
end
%% For declaration of the Result of Program
fprintf(1,' %4.1f %12.2f %d\n', alp_vct(a), SNR,Keys);
% Vector
a=a+1;
end
% End Program