Piano notes synthesis with karplus-strong algorithm
11 次查看(过去 30 天)
显示 更早的评论
Hi, i am trying to make the A4 piano note in matlab but i didn't understand how to use the FIR filter in this page: https://www.mathworks.com/help/signal/examples/generating-guitar-chords-using-the-karplus-strong-algorithm.html .I implemented the Karplus- Strong part of my code. Now, what i want to do is filtering the "signal" output from the karplus(), and get the piano sound. In matlab help link, they did a similar thing to what i want but i didn't understand the syntax of firls() function. In every harmonic, i should be able to select a different gain so that i can control the contribute of every harmonic and get the pitch of a piano sound. Is this a good approach by the way?(FIR filter)
%% freqHz : frequency in Hz (rouding occurs when computing delay line!)
% iterations : # of loops (duration of sound file)
% fs : sampling frequency
function signal = karplus(freqHz, iterations, fs)
% Echo some useful information
N = fs/freqHz;
N = floor(N);
x = 2*rand(1,N);
x = x - mean(x);
% generate noise and init. delay line
% make sure burst and delay line agree: burst >= delay line
% ---------------------------------------------------------------------------
y = [zeros(1,N+1)];
if iterations > length(x)
diff = iterations - length(x);
x = [x zeros(1,diff)];
end
% Filtering
% y[n] = x[n] + 0.5 y[n-N] + 0.5 y[n-(N+1)]
% ---------------------------------------------------------------------------
% init.
out = 0;
signal = 0;
lengthYOffset = length(y)-1;
for i=1:iterations
out = x(i) + 0.5*(y(N) + y(N+1));
% filter signal
y = [out, y(1:lengthYOffset)];
% update delay line
signal = [signal out];
end
% Play sound and plot% ---------------------------------------------------------------------------
plot(signal), grid on,title('Simple Karplus Strong algorithm'),sound(signal, fs)
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Filter Design 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!