Time-Frequency analysis using WAV file

Hello Team,
As a part of project I need to plot frequency- time plot of WAV file. Anyway I have figured out plotting the graph using some external code (Examples) and now I have a issue how do I get the plot in milliseconds as time on x-axis since my wav file is of 60 seconds and I have to do deep analysis of graph by give limits to time and clear graph. Here I attach the code that i'm using and the graphs..
clear, clc, close all
[x, fs] = audioread('test.wav');
x = x(:, 1);
xlen = length(x);
t = (0:length(x)-1)/fs;
plot(t*1E+3, x);
wlen = 1024;
nfft = 4*wlen;
hop = wlen/4;
TimeRes = wlen/fs;
FreqRes = 2*fs/wlen;
TimeResGrid = hop/fs;
FreqResGrid = fs/nfft;
w1 = hanning(wlen, 'periodic');
[~, fS, tS, PSD] = spectrogram(x, w1, wlen-hop, nfft, fs);
Samp = 20*log10(sqrt(PSD.*enbw(w1, fs))*sqrt(2));
w2 = hanning(xlen, 'periodic');
[PS, fX] = periodogram(x, w2, nfft, fs, 'power');
Xamp = 20*log10(sqrt(PS)*sqrt(2));
figure(1)
subplot(3, 3, [2 3])
plot(t, x)
grid on
xlim([0 max(t)])
ylim([-1.1*max(abs(x)) 1.1*max(abs(x))])
set(gca, 'FontName', 'Times New Roman', 'FontSize', 12)
xlabel('Time, s')
ylabel('Amplitude')
title('The signal in the time domain')
subplot(3, 3, [4 7])
plot(fX, Xamp)
grid on
xlim([0 max(fX)])
ylim([min(Xamp)-10 max(Xamp)+10])
view(-90, 90)
set(gca, 'FontName', 'Times New Roman', 'FontSize', 12)
xlabel('Frequency, Hz')
ylabel('Magnitude, dB')
title('Amplitude spectrum of the signal')
subplot(3, 3, [5 6 8 9])
surf(tS, fS, Samp)
shading interp
axis tight
box on
set(gca, 'FontName', 'Times New Roman', 'FontSize', 12)
xlabel('Time, s')
ylabel('Frequency, Hz')
title('Amplitude spectrogram of the signal')
view(0, 90)
hcol = colorbar('East');
set(hcol, 'FontName', 'Times New Roman', 'FontSize', 12)
ylabel(hcol, 'Magnitude, dB')
disp(['Frequency resolution of the analysis: ' num2str(FreqRes) ' Hz'])
disp(['Time resolution of the analysis: ' num2str(TimeRes) ' s'])
disp(['Resolution of the frequency grid: ' num2str(FreqResGrid) ' Hz'])
disp(['Resolution of the time grid: ' num2str(TimeResGrid) ' s'])
view(-45,65)
colormap bone

5 件のコメント

John Marriott
John Marriott 2020 年 5 月 26 日
Hi Venkata,
Im not sure I understand your problem - do you wish to plot all 60 seconds of the time series but with the x axies displaying milliseconds in which case you would just need to use the set the xtick properties e.g set( gca, 'Xtick', [0 20 40 60]/1000) and then set the xlabel to 'Time ms' or do you wish to plot just a snippet of the data with each point on the x axis indicating 1 milliecond?
Venkata Naga Rohith Tinnanuru
Venkata Naga Rohith Tinnanuru 2020 年 5 月 26 日
Hi John,
Thanks for your reply and I want each point on x-axis indicating milliseconds anyway by zooming graph we will get into milliseconds and i'm thinking is there any syntax so that I get into milliseconds without zooming the graph.
John Marriott
John Marriott 2020 年 5 月 27 日
Hi Venkata
for you figure subplot(3,3,[2 3])
we can plot easily the time as milliseconds e.g plot(t*1E+3, x);
this has been shown on a previous post https://uk.mathworks.com/matlabcentral/answers/369037-plot-time-of-audio-file-in-milliseconds
but in order to include a xtick or point of x axis for every 1 millisecond we would need to set the xtick propteris e.g using set(gca, 'XTick',[0:60000])
note however that this would be almost impossible to see on a normal sized screen - with this resolution on the x axis, plotting my own audio data i was only able to accurately read 100 milliseconds of data at any one time.
Venkata Naga Rohith Tinnanuru
Venkata Naga Rohith Tinnanuru 2020 年 5 月 27 日
Hello John, thanks for your advice and i'll look into it and if I have any questions i'll post in community.
Nega Ejjigu
Nega Ejjigu 2021 年 9 月 2 日
Can somebody help on to edit the above code so it would accept 2 .wav files then to plot in one graph?
Only I need Amplitude spectrum figure (freq Vs magnitude)
Appreciated in advance for help

サインインしてコメントする。

回答 (1 件)

Nega Ejjigu
Nega Ejjigu 2021 年 9 月 4 日

0 投票

wondering if some one able to rewrite the above code to accept 2 wav files input then two plot just frequency domain in one plot
Thanks for help in advance

1 件のコメント

Walter Roberson
Walter Roberson 2021 年 9 月 4 日
This is not an Answer to the Question that was asked, and you need to create completely different plots than are used here.

サインインしてコメントする。

製品

リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by