Borrar filtros
Borrar filtros

how to plot log frequency spectrogram of an audio signal in .wav format

3 visualizaciones (últimos 30 días)
danny Sharah
danny Sharah el 10 de Abr. de 2015
Editada: Mann Baidi el 26 de Feb. de 2024
need a code to plot pitch contour. for this i need log frequency spectrogram...please help

Respuestas (1)

Mann Baidi
Mann Baidi el 26 de Feb. de 2024
Editada: Mann Baidi el 26 de Feb. de 2024
Hi Danny,
As per my assumption, you would like to plot pitch contour for a sound file with the help of log frequency spectogram.
For the frequency spectogram, you can use the "spectrogram" function in MATLAB. After this, you can plot the pitch contour by finding the maximum frequency and then plotting the corresponding frequency.
Here is an example code:
% Read the audio file
[y, Fs] = audioread('<your_audio_file>.wav');
window_size = 1024; % Window size for spectrogram
overlap = 512; % Overlap between consecutive windows
nfft = 1024; % Number of FFT points
% Compute the spectrogram
[S, F, T] = spectrogram(y, hamming(window_size), overlap, nfft, Fs);
% Compute the pitch contour
pitch_contour = zeros(1, size(S,2)); % Initialize pitch contour vector
for i = 1:size(S,2)
[~, max_idx] = max(abs(S(:,i))); % Find the index of the maximum magnitude
pitch_contour(i) = F(max_idx); % Get the corresponding frequency
end
% Plot the pitch contour
figure;
plot(T, pitch_contour);
xlabel('Time (s)');
ylabel('Frequency (Hz)');
title('Pitch Contour');
You can learn more about the 'spectrogram' function by reffering to the following link:
Also, please check whether you have the Signal Processing Toolbox licesnse, For using spectrogram, you need to have the particular license.
Hope this answer will help you with your issue!

Categorías

Más información sobre Time-Frequency Analysis en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by