How can I read multiple .wav files and plot them as separate signals?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
prodeje
am 10 Apr. 2020
Kommentiert: GreyHunter
am 3 Okt. 2020
Hello,
I am pretty new to Matlab, and am currently struggling with a task. So basically, I need to read data from 2 .wav files and create a graph of these ?1(?) and ?2(?) respectively audio signals with time domains on the x-axis, then make a sum s3(n) of those signals, and display it alongside the initial 2. Any help would be appreciated.
2 Kommentare
Peng Li
am 10 Apr. 2020
You could read them separately using audioread function. It just needs the directory of each wave file and returns the signal as the first outcome, and sampling frequency as the second.
Akzeptierte Antwort
Ameer Hamza
am 10 Apr. 2020
Bearbeitet: Ameer Hamza
am 10 Apr. 2020
For the case of two signals, try this
[wave1,fs1]=audioread('Voice1.wav');
[wave2,fs2]=audioread('Voice2.wav');
t1 = linspace(0, (numel(wave1)-1)/fs1, numel(wave1));
t2 = linspace(0, (numel(wave2)-1)/fs2, numel(wave2));
subplot(2,1,1)
plot(t1, wave1);
subplot(2,1,2)
plot(t1, wave1);
For multiple files, use this
names = {'Voice1.wav', 'Voice2.wav', 'Voice3.wav', 'Voice4.wav'};
wave = cell(size(names));
fs = cell(size(names));
subplot_cols = 3;
subplot_rows = ceil(numel(names)/subplot_cols);
for i=1:numel(names)
[wave{i},fs{i}]=audioread('sample.wav');
t = linspace(0, (numel(wave{i})-1)/fs{i}, numel(wave{i}));
subplot(subplot_rows,subplot_cols,i)
plot(t1, wave1);
title(['File: ' names{i}]);
end
If the names of all files follow a similar pattern, then try something like this
files = dir('Voice*.wav'); % get names of all files of pattern Voice1.wav, Voice2.wav, Voice3.wav, ...
names = {files.name};
wave = cell(size(names));
fs = cell(size(names));
subplot_cols = 3;
subplot_rows = ceil(numel(names)/subplot_cols);
for i=1:numel(names)
[wave{i},fs{i}]=audioread('sample.wav');
t = linspace(0, (numel(wave{i})-1)/fs{i}, numel(wave{i}));
subplot(subplot_rows,subplot_cols,i)
plot(t1, wave1);
title(['File: ' names{i}]);
end
3 Kommentare
Ameer Hamza
am 3 Okt. 2020
Can you write a new question with details of how your files are structued? Paste the link in the comment. If possible, I will try to answer.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Audio and Video Data 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!