How can I read multiple .wav files and plot them as separate signals?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Peng Li
le 10 Avr 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.
Réponse acceptée
Ameer Hamza
le 10 Avr 2020
Modifié(e) : Ameer Hamza
le 10 Avr 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 commentaires
Ameer Hamza
le 3 Oct 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Audio and Video Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!