Two examples of frequency manipulation

Solution



function x = synth(tone,freqs,amps,numf,nums,Fs,r)
% synthethizes the sound given by the frequencies freqs and their
% amplitude amps, with a shift in a number tone of musical half tones
% numf is the number of frequencies
% nums is the number of samples; Fs the sampling frequency
% x is normalized by the largest amplitude
% amplitudes are in decreasing order
% r is an amplification (or attenuation) factor
% that is applied to the normalized signal
x = zeros(length(nums),1);
T=1/Fs;
t=[0:nums-1]*T;
tones = halftones(tone);
freqs = freqs*tones;
for i = 1:numf
ff = freqs(i);
amp = amps(i);
x = x+amp*sin(2*pi*ff*t)';
end
x=x*r/amps(1);