How to extract frequency and time components of an existing audio 'sound.wav' file?

12 ビュー (過去 30 日間)
I'm new in signal processing and I'm a bit confused.
I've created my own signal to create '*.wav' file. Here is the code below i used to create.
frq = [600 700 600 450 300 600 700 600 450 300 600 700 600 450 900 700 600 ];
time = [4000 1500 1750 1500 5000 4000 1500 1750 1500 5000 4000 1500 1750 1500 8000 3000 5000];
fs=8192; j=1;
for i=1:length(frq)
song= [song sin(2*pi*frq(i)*[1:time(j)]/fs)];
total_time=total_time+time(j);
j=j+1;
end
audiowrite('Sound.wav',song,8192);
So my goal is; i want to analyze this 'sound.wav' file and recreate the song. When i use 'fft' like code below, i get the frequencies i got but not in order of course.
[audioIn,fs] = audioread('Sound.wav');
songdft=fft(audioIn);
freq= 0:fs/length(audioIn):fs/2;
songdft=songdft(1:length(audioIn)/2+1);
[~,peaklocs] = findpeaks(abs(songdft));
figure;plot(freq,abs(songdft)); xlabel('Frequency'); xlabel('Frequency');
So when i used spectrogram function i started to thinking that, this function could be my solution because at the plot, frequencies and durations of each sounds clearly can be seen. But i don't know how to exract components from spectrogram plot. Can anyone help me on this?
spectrogram(audioIn,blackman(500),100,150,fs);

採用された回答

Star Strider
Star Strider 2020 年 5 月 16 日
It’s possible to recover much of that information in the signal:
[s,f,t] = spectrogram(audioIn,blackman(500),100,150,fs);
[smx,trow] = max(abs(s),[],1); % Time Indices Of Maximum ‘s’
frqv = f(trow); % Frequencies For Each Time
figure
plot(t, frqv)
grid
xlabel('Time')
ylabel('Frequency')
This gives the appproximate frequencies and the approximate times for the durations of each one.
It would probably be possible to recover the signal, depending on how much information you want to carry over from the original code that created ‘song’.
  2 件のコメント
berker caner
berker caner 2020 年 5 月 17 日
Wow! Star Strider answered my question! You are my hero in this plotform since i started the signal processing. Anyway; i had another solution after i asked and it works but for your honor I'm gonna use yours. Thank you for your answer!
Star Strider
Star Strider 2020 年 5 月 17 日
As always, my pleasure!
How did you solve it?
.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMeasurements and Spatial Audio についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by