Info
This question is closed. Reopen it to edit or answer.
What does this particular code do?
1 view (last 30 days)
Show older comments
Hi everyone, I am a bit unfamiliar with the signal analysis part of Matlab and I have to work with this part of code for an assignment. I almost have no idea of what each command is set to do and accomplish. I would be really grateful if you could help me understand the process and purpose of the commands. Thanks a lot in advance!! (I use the R2015a).
Fs = 44100;
A = 196; % The A string of a guitar is normally tuned to 110 Hz.
Eoffset = -5;
Doffset = 5;
Goffset = 10;
Boffset = 14;
E2offset = 19;
F = linspace(1/Fs, 1000, 2^12);
x = zeros(Fs * 4, 1);
delay = round(Fs/A);
b = firls(42, [0 1/delay 2/delay 1], [0 0 1 1]);
a = [1 zeros(1, delay) -0.5 -0.5];
Hd = dfilt.df1(b, a);
[H,W] = freqz(Hd, F, Fs);
plot(W, 20*log10(abs(H)));
title('Harmonics of an open A string');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
Hd.PersistentMemory = true;
Hd.States.Numerator = rand(42, 1);
Hd.States.Denominator = rand(delay+2, 1);
note = filter(Hd, x);
note = note-mean(note);
note = note/max(abs(note));
hplayer = audioplayer(note, Fs);
play(hplayer);
1 Comment
Answers (1)
Abhishek Kumar
on 26 Jun 2019
Hi Petros
It seems that the code provided by you is trying to replicate the sound produced after plucking the 'A' string of a guitar. If thats the case, then the code seems to be workin fine.
The code uses Karplus-Strong algorithm.
All the functions used in the code have been properly explained in the documentation. Please go through the documentation if you need assitance with understanding the functions.In the command window of Matalb type:
>> help linspace
and you will know what your code does.
The variables defined at the top are your input. i.e F is the sampling rate choosen by you. A being the the frequency of the 'A' string of the guitar.
This exact same algorithm has been explained here:
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!