How can I read multiple .wav files and plot them as separate signals?

3 views (last 30 days)
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 Comments
Peng Li
Peng Li on 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.
prodeje
prodeje on 10 Apr 2020
So for example:
[wave1,fs1]=audioread('Voice1.wav');
[wave2,fs2]=audioread('Voice2.wav');
And then how should I plot them as separate signals in a graph? Thanks.

Sign in to comment.

Accepted Answer

Ameer Hamza
Ameer Hamza on 10 Apr 2020
Edited: Ameer Hamza on 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 Comments
Ameer Hamza
Ameer Hamza on 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.

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!