Choose frequency to plot and create sound
Show older comments
I have the variable k, which is equal to n*pi (n = 1,2,3,4,5,6). Is there any way to have all the values of k and choose every time one of them to plot and create sound of sin(k).
Answers (1)
Star Strider
on 24 Feb 2023
Edited: Star Strider
on 24 Feb 2023
These frequencies are going to be too low to hear, so consider multiplying them by perhaps 100 in the sound call.
Fs = 44100; % Sampling Frequency (Hz)
Tlen = 10; % Signal Length (sec)
t = linspace(0, Tlen*Fs, Tlen*Fs+1)/Fs;
freq = pi*(1:6);
for k = 1:numel(freq)
chooseFreq = randi(numel(freq))
sv(:,k) = sin(t*freq(chooseFreq)).';
% sound(sv(:,k),Fs)
% pause(Tlen)
figure
plot(t, sv(:,k))
xlim([0 5])
title(sprintf('Frequency = %.2f',freq(chooseFreq)))
end
EDIT — (24 Feb 2023 at 23:34)
.
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



