How can I generate 9 sounds on matlab at 100Hz, 500ms long, 20ms rise and fall, that each have a different timbre?
7 views (last 30 days)
Show older comments
How can I generate 9 sounds on matlab at 100Hz, 500ms long, 20ms rise and fall, that each have a different timbre?
0 Comments
Answers (1)
Star Strider
on 19 May 2015
One possible approach:
Fs = 44100; % Sampling Frequency
Ts = 1/Fs; % Sampling Interval (s)
T = 0:Ts:(Fs*Ts); % One Second
Frq = 100; % Fundamental Frequency
Len = 0.5; % Length Of Sound (s)
t = linspace(0, 2*pi*Frq, fix(Len*Fs)); % Length = 0.5s
rise = [0:Fs/5*0.1]/(Fs/5*0.1); % Rise-Fall
Env = [rise ones(1,size(t,2)-2*length(rise)) fliplr(rise)];
for k1 = 1:9
S(k1,:) = k1*sum(sin([1:k1:2*k1]'*t)).*Env;
pause(1)
sound(S(k1,:))
end
%
figure(1)
plot(T(1:length(Env)), Env)
grid
title('Envelope')
xlabel('Time (s)')
ylabel('Amplitude')
The ‘Env’ assignment is the envelope to produce the desired rise and fall. The plot call plots it, and is simply there to demonstrate its shape and is not necessary for the code.
The ‘S’ matrix stores all the sounds in one (9x22050) matrix.
I’m not exactly sure what you mean by ‘timbre’, however all these have a fundamental frequency of 100 Hz, with varying harmonics.
This will provide you with code to begin whatever project you are working on. You will have to experiment with it to get the result you want.
Have fun!
0 Comments
See Also
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!