Piano notes synthesis with karplus-strong algorithm

조회 수: 11 (최근 30일)
Berkay Güler
Berkay Güler 2020년 7월 17일
편집: Berkay Güler 2020년 7월 17일
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개)

카테고리

Help CenterFile Exchange에서 Filter Design에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by