Reputation: 2049
I have a large file with values, I'm trying to create a waveform with those values.
It takes too long, and since I'm not the best at Octave, I think there may be another way to do this. I'm looking for a faster alternative, one that uses Octave's array handling capabilities instead of me doing a loop, which I assume is slow.
EDIT
csv
is a [1xn] array.
csv = csvread('values.csv');
n = length(csv);
t = [0 : 1 / (freq * spc) : 1 / freq];
t = t(2 : length(t));
wave = csv(1) * sin(two_pi_freq * t);
for i = 2 : n
wave = [wave (csv(i) * sin(two_pi_freq * t))];
endfor
Upvotes: 1
Views: 359
Reputation: 11812
Edited answer based on latest comments:
To avoid any for
loop, you can multiply your two vectors to obtain an array, then reshape the array to put all the values in line.
The way you are building t
, it will be of dimension [1xm] (with m=length(t)
)
For a csv
vector of dimension [1xn], instead of your loop, use:
%// generate an array size [nxm] by multiplying [nx1] * [1xm]
wave2 = csv.' * sin(two_pi_freq * t) ;
wave2 = reshape( wave2.' , [] , length(t)*length(csv) ) ; %// reshape the array in one [1xm*n] line
This should replace your last 4 lines of code (the first definition of wave
and the 3 lines of the loop.
Upvotes: 2