Formation of audio file(.wav) from a matrix.

4 ビュー (過去 30 日間)
HEMRAJ PATEL
HEMRAJ PATEL 2021 年 11 月 17 日
コメント済み: Star Strider 2021 年 11 月 17 日
How can i convert a simple 3*3 matrix into an audio file of (.wav)

採用された回答

Rick Nickle
Rick Nickle 2021 年 11 月 17 日
編集済み: Rick Nickle 2021 年 11 月 17 日
Thanks Star Strider!
Hemraj, I understood that you were also interested in writing the .WAV file, so I'll add that.
Populate the 3x3 matrix:
M=randn(3)
M = 3×3
-0.7170 -2.0392 -0.5122 1.0327 0.1710 -0.7445 1.5918 -1.4577 0.2902
Set the sample rate:
Fs=48000
Fs = 48000
Normalize the data and put it back into 3x3 (I may missing a good optimization here):
y = reshape(normalize(M(:),'range',[-1 1]),3,3)
y = 3×3
-0.2718 -1.0000 -0.1589 0.6920 0.2174 -0.2869 1.0000 -0.6798 0.2830
Write the data to .wav:
audiowrite('3x3.wav', y, Fs)
Now read it back to test:
[yy, FFs] = audioread('3x3.wav')
yy = 3×3
-0.2718 -1.0000 -0.1590 0.6920 0.2174 -0.2869 1.0000 -0.6798 0.2830
FFs = 48000
We can't actually play back using the sound() function because it only supports 2-channel, so play back the first two:
sound(yy(1:end,[1 2]))
  1 件のコメント
Star Strider
Star Strider 2021 年 11 月 17 日
My pleasure.
With extremely rare exceptions (this is not one), I delete my un-accepted Answers, so I have here as well.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulation, Tuning, and Visualization についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by