Stuck with for loop with harmonic frequency algorithm
5 次查看(过去 30 天)
显示 更早的评论
Hello, I'm ultimately trying to configure a script to analyse the composition of waveforms in a signal generator and I'm strugling to find a way to do this neatly:
y1 = A(1) * sin(linspace(0, nSeconds * Harm(1) * 2* pi, nSeconds*Fs)); y2 = A(2) * sin(linspace(0, nSeconds * Harm(2) * 2* pi, nSeconds*Fs));
etc... Where A(#)=amplitude from another for loop Harm(#) = harmonic frequency from the other for loop.
I ideally want y(i) = A(i) * ....Harm(i).... but I'm unsure of how to do this with the sinusoid being an array of length nSeconds*Fs.
Any help greatly appreciated.
0 个评论
采纳的回答
A Jenkins
2013-10-28
for idx=1:length(A)
y(idx,:) = A(idx) * sin(linspace(0, nSeconds * Harm(idx) * 2* pi, nSeconds*Fs))
end
2 个评论
A Jenkins
2013-10-28
I'm sure 'i' would work as well, but 'i' is also the imaginary number sqrt(-1), so it is bad practice to overwrite it with your counter variable, and confusing/dangerous to those of us who use it to mean sqrt(-1).
I would guess the problem you were having before is that you need the extra colon, y(idx,:) since your y is a vector. The extra colon says: "put the result in 'y', in the row 'idx', and use as many columns ':' as it takes."
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!