how to make an audio

2 views (last 30 days)
caitlyn
caitlyn on 26 Nov 2022
Commented: Star Strider on 27 Nov 2022
i want to know how to generate a stereo audio matrix in matlab and make tones of different frequencies
  1 Comment
Jan
Jan on 26 Nov 2022
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.

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 26 Nov 2022
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 Comments
caitlyn
caitlyn on 27 Nov 2022
Edited: caitlyn on 27 Nov 2022
what lol i just want to know how to generate the sound
Star Strider
Star Strider on 27 Nov 2022
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!