how to make an audio

1 次查看(过去 30 天)
caitlyn
caitlyn 2022-11-26
评论: Star Strider 2022-11-27
i want to know how to generate a stereo audio matrix in matlab and make tones of different frequencies
  1 个评论
Jan
Jan 2022-11-26
As I have asked in your deleted question already: What have you tried so far? What is your question concering Matlab?
You do not have to delete a question to insert new details. Questions can be edited.

请先登录,再进行评论。

回答(1 个)

Star Strider
Star Strider 2022-11-26
I would use a Gaussian for the envelope function, similar to:
envfcn = @(ct,sf,t) exp(-(t-ct).^2*sf);
where ‘t’ is the time vector, ‘ct’ is the centre time of the Gaussian function, and ‘sf’ is the scaling factor so that the envelope function has the correct shape (width). Experiment with ‘envfcn’ first so you understand how it works (plot it), then create the tones and do an element-wise multiplication of the tone vector and the envelope function.
That is how I would approach this, anyway.
Then check the result using the pspectrum function, similar to this analysis of the provided example —
Uz = unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1208748/sample1.zip');
[y,Fs] = audioread(Uz{1});
L = size(y,1);
t = linspace(0, L-1, L)/Fs;
figure
plot(t, y)
grid
[p1,f1,t1] = pspectrum(y(:,1),Fs,'spectrogram');
[p2,f2,t2] = pspectrum(y(:,2),Fs,'spectrogram');
figure
waterfall(f1,t1,p1')
xlabel('Frequency (Hz)')
ylabel('Time (seconds)')
wtf = gca;
wtf.XDir = 'reverse';
view([30 45])
xlim([0 4E3])
title('Left Channel')
figure
waterfall(f2,t2,p2')
xlabel('Frequency (Hz)')
ylabel('Time (seconds)')
wtf = gca;
wtf.XDir = 'reverse';
view([30 45])
xlim([0 4E3])
title('Right Channel')
Since this is your assignment, I leave the rest to you.
.
  2 个评论
caitlyn
caitlyn 2022-11-27
编辑:caitlyn 2022-11-27
what lol i just want to know how to generate the sound
Star Strider
Star Strider 2022-11-27
What I wrote here tells you haow to analyse the result.
To crreate the sound, use the sin function. Create a time vector for all the different sine vectors you want to create (it will have to be long enough to accommodate the entire time, so 6 seconds), then create a matrix of the different frequencies, apply the envelope function to each one, and save the result in a matrix.
Example —
envfcn = @(ct,sf,t) exp(-(t-ct).^2*sf);
Fs = 44100; % Sampling Frequency
t = linspace(0, Fs-1, Fs)/Fs;
s = sin(2*pi*1500*t);
env = envfcn(0.66,64,t);
se = s .* env;
figure
plot(t, se)
grid
Make appropriate changes to this example code, and complete your assignment.
I will let you figure out how the code works.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Multirate Signal Processing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by