Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

What does this particular code do?

조회 수: 1 (최근 30일)
Petros Tsitouras
Petros Tsitouras 2019년 5월 8일
마감: MATLAB Answer Bot 2021년 8월 20일
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개)

Abhishek Kumar
Abhishek Kumar 2019년 6월 26일
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:

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by