How can I read multiple .wav files and plot them as separate signals?
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Peng Li
2020 年 4 月 10 日
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.
採用された回答
Ameer Hamza
2020 年 4 月 10 日
編集済み: Ameer Hamza
2020 年 4 月 10 日
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 件のコメント
Ameer Hamza
2020 年 10 月 3 日
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Audio and Video Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!