フィルターのクリア

How to save two sin waves with left and right channels in a stereo wav file?

30 ビュー (過去 30 日間)
Omer Asif
Omer Asif 2017 年 3 月 3 日
コメント済み: An 2024 年 2 月 6 日
Hi,
I am using audiowrite to save two sin waves. Here is my code.
fs = 8000; %frequency sample rate
i=1/fs; % interval
t = 0:i:2; % time
phi = 0;
% F = 220Hz
f = 220;
x = A*sin((2*pi*f*t) + phi);
% F = 240Hz
f = 240;
y = A*sin((2*pi*f*t) + phi);
filex = 'x.wav';
filey = 'y.wav';
audiowrite(filex,x,fs);
audiowrite(filey,y,fs);
Now I want to save two separate waves as left and right channels in the a stereo wav file. How can I do that.
Many Thanks!

採用された回答

Star Strider
Star Strider 2017 年 3 月 3 日
編集済み: Star Strider 2017 年 3 月 3 日
To create a stereophonic sound file, you need to create a (Nx2) matrix, so each channel is a column vector. In this example, ‘x’ will be the left channel, and ‘y’ will be the right channel.
The Code
fs = 8000; %frequency sample rate
i=1/fs; % interval
t = 0:i:2; % time
phi = 0;
A = 1;
% F = 220Hz
f = 220;
x = A*sin((2*pi*f*t) + phi);
% F = 240Hz
f = 240;
y = A*sin((2*pi*f*t) + phi);
stereo_mtx = [x(:), y(:)];
audiowrite('stereo sound.wav', stereo_mtx, fs);
  3 件のコメント
Star Strider
Star Strider 2017 年 3 月 3 日
My pleasure!
An
An 2024 年 2 月 6 日
When saving to a file, stereo is lost. Any way to fix this?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDetection, Range and Doppler Estimation についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by