Scaled frequency magnitude spectrum using FFT
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Could someone please check and advise if the MatLab code shown below is correct to plot the scaled time waveform and the scaled frequency magnitude spectrum? I wish to get a sharp spike, remove the side-lobes, and get something as shown below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1128885/image.jpeg)
close all;
clear all;
clc;
audioread('DTMFDigit3.wav');
info = audioinfo('DTMFDigit3.wav');
display(info);
[Dialtone, fs] = audioread('DTMFDigit3.wav');
sound(Dialtone, fs)
N = length(Dialtone);
idx = 0:N-1;
t = idx*(1/fs);
figure(1);
plot(t, Dialtone)
title('Dial Tone Time Waveform'); % plot title3
xlabel('Time'), ylabel('Amplitude'); % plot axis labels
N= 2^nextpow2(N);
k=(-N/2):1:(N/2)-1;
f=(fs/N)*k;
FFT_dialtone = fft(Dialtone,N);
FFT_dialtone = abs(fftshift(FFT_dialtone))/N;
figure(2);
plot(f,FFT_dialtone);
xlabel('Frequecy -fs/2 to fs/2');
ylabel('Magnitude');
title('Spectrume of dialtone');
0 Kommentare
Antworten (1)
Rahul
am 24 Feb. 2023
Bearbeitet: Rahul
am 24 Feb. 2023
As per the audio file "DTMFDigit3.wav", it seems that you are trying to extract the frequency information of DTMF digit 3 dialtone. As per the DTMF frquency table given in wikipedia page, the frequencies associated with it are 697 Hz and 1477 Hz. The plot that you have provided is for DTMF digit 0 dialtone. Nevertheless, you can use following code to extract the frequency information of any signal.
close all;
clearvars;
clc;
%% Read the audio file
info = audioinfo('DTMFDigit3.wav');
display(info);
[Dialtone, fs] = audioread('DTMFDigit3.wav');
sound(Dialtone, fs) % play the audio file
N = length(Dialtone); % extract the length of the signal
t = (0:N-1)*(1/fs); % time period of the signal
figure(1);
plot(t, Dialtone)
title('Dial Tone Time Waveform');
%% Extract the frequency information of the dialtone using FFT
Y = fft(Dialtone);
% Compute the two-sided spectrum P2.
% Then compute the single-sided spectrum P1 based
% on P2 and the even-valued signal length L.
P2 = abs(Y/N);
P1 = P2(1:N/2+1);
P1(2:end-1) = 2*P1(2:end-1);
%% Plot the frequency spectrum
f = fs*(0:(N/2))/N;
figure(2)
plot(f,P1)
title("Single-Sided Amplitude Spectrum of X(t)")
xlabel("f (Hz)")
ylabel("|P1(f)|")
%% remove the unwanted sidelobes using thresholding
thresh_val = 0.02;
P1_smooth = zeros(1, length(f));
for ii = 1:length(f)
if P1(ii)>thresh_val
P1_smooth(ii) = P1(ii);
end
end
figure(3)
plot(f, P1_smooth)
title("Single-Sided Smoothed Amplitude Spectrum of DTMF Digit 3")
xlabel("f (Hz)")
ylabel("|P1 smooth|")
0 Kommentare
Siehe auch
Kategorien
Mehr zu DTMF finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!