How to extract frequency and time components of an existing audio 'sound.wav' file?
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
berker caner
am 16 Mai 2020
Kommentiert: Star Strider
am 17 Mai 2020
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);

0 Kommentare
Akzeptierte Antwort
Star Strider
am 16 Mai 2020
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Measurements and Spatial Audio 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!