Choose frequency to plot and create sound

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)

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
chooseFreq = 6
chooseFreq = 2
chooseFreq = 1
chooseFreq = 5
chooseFreq = 4
chooseFreq = 4
EDIT — (24 Feb 2023 at 23:34)
Added pause call (currently commented out).
.

Asked:

on 24 Feb 2023

Edited:

on 24 Feb 2023

Community Treasure Hunt

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

Start Hunting!