How to add delay
    9 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
function [dtmf_output] = Key_generator(dial_num)
%
%               Function to generate the DTMF signals
%
%  
%  Inputs:
%          dial_num =  Number that is dialled
%      
%          
%  Outputs:
%          dtmf_output = the combination of two sinesoids corresponding to the
%                        numbers dialled and saved as wav file
%
%
NoisePow=0;  %Noise
Num_of_samples=1000;
Fs = 8000;            % Sampling frequency
Ts = 1/Fs;            %Period
T = Ts*(0:Num_of_samples-1)';
x = (dial_num);
ss = [];
for i = 1:8
    switch x(i)
        case '0'
            F1 = 941;
            F2 = 1336;
        case '1'
            F1 = 697;
            F2 = 1209;
        case '2'
            F1 = 697;
            F2 = 1336;
        case '3'
            F1 = 697;
            F2 = 1477;
        case 'A'
            F1 = 697;
            F2 = 1633;
        case '4'
            F1 = 770;
            F2 = 1209;
        case '5'
            F1 = 770;
            F2 = 1336;
        case '6'
            F1 = 770;
            F2 = 1477;
        case 'B'
            F1 = 770;
            F2 = 1633;
        case '7'
            F1 = 852;
            F2 = 1209;
        case '8'
            F1 = 852;
            F2 = 1336;
        case '9'
            F1 = 852;
            F2 = 1477;
        case 'C'
            F1 = 852;
            F2 = 1633;
        case '*'
            F1 = 941;
            F2 = 1209;
        case '#'
            F1 = 941;
            F2 = 1477;
        otherwise
            F1 = 941;
            F2 = 1633;
    end
    first_sine = cos(2*pi*F1*T);           % first sinusoidal signal
    second_sine = cos(2*pi*F2*T);           % second sinusoidal signal
    %dtmf_output = first_sine + second_sine;
    d = first_sine + second_sine;
    %%%   Adding noise to the generated DTMF output
    % NoisePow  has to be below 5 for getting the correct decode output
    dtmf_output = d + NoisePow * rand(size(d));  % Generating Tones
    V2 = dtmf_output/ max(abs(dtmf_output)); %To avoid clipping
    ss(i,:) = V2;
    filename = strcat('Key',int2str(i),'.wav');  %saving each of the 8 numbers in different wav files 
    audiowrite(filename,V2, Fs);
    %Ploting fft
    w = fft(V2);
    N = length(V2);
    f = (0:N-1)/N*Fs;
    figure();
    plot(f, abs(w))
    xlabel('Frequency (Hz)')
    ylabel('Amplitude')
    title(sprintf('FFT Amplitude Spectrum for key %d',i))
    ylim([0 300])
    xlim([0 2000])
    grid on
    %ploting the DTMF Input Keys
    figure();
    plot(T,V2)
    title(sprintf('Time domain for Key %d',i));
    xlabel('Time');
    ylabel('Amplitude');
    xlim([0 0.07])
    grid on
    %function that generate sound in matlab
    % soundsc(V2);
    %pause(0.5)
end
%Saving all 8 numbers in one wav file
y = [];
for i = 1:8
    [y1 Fs] = audioread(strcat('Key',int2str(i),'.wav'));
    y = [y; y1];
end
%I need to delay this by 50ms
T = Ts*(0:8000-1)';
plot(T,y)
audiowrite('DialedNumber.wav',y, Fs);

0 comentarios
Respuestas (1)
  Suraj Kumar
 el 18 de Mzo. de 2025
        To introduce a delay between each DTMF signal generated by your Key_generator function, you can add a period of silence between the signals. This is accomplished by appending a vector of zeros (representing silence) between each generated tone. You can refer to the following steps and updated code snippet for more information :
1. You can define a variable silence_duration to specify the length of the silence period in seconds (50 milliseconds in this case).A vector of zeros, silence_samples, is created to represent the silence period. The length of this vector is determined by multiplying the sampling frequency (Fs) by the silence_duration.
2. In the loop where each DTMF signal is read and concatenated,you can add the silence_samples vector between the signals. This effectively adds a 50 ms delay between each DTMF tone.
You can refer to the attached code snippet :
silence_duration = 0.05;
silence_samples = zeros(round(Fs * silence_duration), 1);
y = [];
for i = 1:8
    [y1, Fs] = audioread(strcat('Key', int2str(i), '.wav'));
    y = [y; y1; silence_samples];  
end
By applying these changes, you can ensure there is a 50 ms pause between each DTMF signal in the output file, resulting in a more realistic dialing sequence.
0 comentarios
Ver también
Categorías
				Más información sobre MATLAB Mobile en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

