DSPRelated.com
Forums

piano synthesis in MATLAB PLZ HELP!

Started by garl...@yahoo.com December 21, 2011
Hello,

I have a question about attempting to synthesize a piano in MATLAB. I am very new to MATLAB and DSP in general and my project is trying to create a piano sound using whatever means (FM synthesis, additive synthesis, etc... whatever is simplest). My program asks the user for a note number (1-88) and should produce the tone with a piano timbre. Right now, I have a signal that is build on the fundamental plus 24 partials with an ADSR envelope for the entire signal. Here is some of the sample code:

srate = 44100;

ff = 27.5*2^((noteNumber-1)/12);

t = (0:1/srate:2);

for i = 1:25
y = y + amp(i)*cos(2*pi*ff*i*t);
end

*Note: amp is a vector that contains coefficients that represent amplitudes of each partial

The sound I am producing is more like that of a kazoo. I know that I need to add the percussive strike of the hammer on the piano strings and some inharmonicities as well but do not know how to go about that? Any help/code would be greatly appreciated. Thank you very much
I would imagine different harmonics decay at different rates; probably
lower harmonics decay slower. You should research this a bit.

On 18 December 2011 20:52, wrote:

> **
> Hello,
>
> I have a question about attempting to synthesize a piano in MATLAB. I am
> very new to MATLAB and DSP in general and my project is trying to create a
> piano sound using whatever means (FM synthesis, additive synthesis, etc...
> whatever is simplest). My program asks the user for a note number (1-88)
> and should produce the tone with a piano timbre. Right now, I have a signal
> that is build on the fundamental plus 24 partials with an ADSR envelope for
> the entire signal. Here is some of the sample code:
>
> srate = 44100;
>
> ff = 27.5*2^((noteNumber-1)/12);
>
> t = (0:1/srate:2);
>
> for i = 1:25
> y = y + amp(i)*cos(2*pi*ff*i*t);
> end
>
> *Note: amp is a vector that contains coefficients that represent
> amplitudes of each partial
>
> The sound I am producing is more like that of a kazoo. I know that I need
> to add the percussive strike of the hammer on the piano strings and some
> inharmonicities as well but do not know how to go about that? Any help/code
> would be greatly appreciated. Thank you very much
>
>