How to solve a loop problem with MATLAB?
-
:confused: I am going to do a signal processing job to a sampled speech signal. I have already done the sampling to a speech signal and got the sampled 60001 values. The next step I am going to do is to normalise the sampled values,i.e. set the maximum value to +1 and the minimum value to -1. By using the function "wavread", the read in data has been put in the range of [-1,+1]. According to what I have found, the maximum value of the sampled 60001 values is 0.9920, while the minimum value is -1. So, my algorithm is to divide all the +ve values with 0.9920. Is it correct? I tried the following program: m = max(sv); % sv is the array containing the sampled 60001 values for k = 1:60001 % sv2 is another array I am going to store the if sv(k)>0 % normalised values. sv2(k) = sv(k)/m % if the element is +ve, divide it with m. else sv2(k) = sv(k) % if the element is 0 or +ve, keep it. end end When running the above, I found that it ran very slowly and I can see the data rolling on the screen of Command Window. Can anyone give me some advice on how to do the loop with C/C++ but using the compiler of MATLAB?
-
:confused: I am going to do a signal processing job to a sampled speech signal. I have already done the sampling to a speech signal and got the sampled 60001 values. The next step I am going to do is to normalise the sampled values,i.e. set the maximum value to +1 and the minimum value to -1. By using the function "wavread", the read in data has been put in the range of [-1,+1]. According to what I have found, the maximum value of the sampled 60001 values is 0.9920, while the minimum value is -1. So, my algorithm is to divide all the +ve values with 0.9920. Is it correct? I tried the following program: m = max(sv); % sv is the array containing the sampled 60001 values for k = 1:60001 % sv2 is another array I am going to store the if sv(k)>0 % normalised values. sv2(k) = sv(k)/m % if the element is +ve, divide it with m. else sv2(k) = sv(k) % if the element is 0 or +ve, keep it. end end When running the above, I found that it ran very slowly and I can see the data rolling on the screen of Command Window. Can anyone give me some advice on how to do the loop with C/C++ but using the compiler of MATLAB?
-
:confused: I am going to do a signal processing job to a sampled speech signal. I have already done the sampling to a speech signal and got the sampled 60001 values. The next step I am going to do is to normalise the sampled values,i.e. set the maximum value to +1 and the minimum value to -1. By using the function "wavread", the read in data has been put in the range of [-1,+1]. According to what I have found, the maximum value of the sampled 60001 values is 0.9920, while the minimum value is -1. So, my algorithm is to divide all the +ve values with 0.9920. Is it correct? I tried the following program: m = max(sv); % sv is the array containing the sampled 60001 values for k = 1:60001 % sv2 is another array I am going to store the if sv(k)>0 % normalised values. sv2(k) = sv(k)/m % if the element is +ve, divide it with m. else sv2(k) = sv(k) % if the element is 0 or +ve, keep it. end end When running the above, I found that it ran very slowly and I can see the data rolling on the screen of Command Window. Can anyone give me some advice on how to do the loop with C/C++ but using the compiler of MATLAB?
qhm wrote: According to what I have found, the maximum value of the sampled 60001 values is 0.9920, while the minimum value is -1. So, my algorithm is to divide all the +ve values with 0.9920. Is it correct? No. This will distort the signal. If you scale an audio signal, you have to scale both halves of it identically. My recommendation would be to leave the data how it is. Is 0.9920 not close enough to 1? The way to scale the audio is just how the wavread function has already - to make the maximum absolute value equal to 1, and scale every value based on that. Further scaling is not necessary.
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
:confused: I am going to do a signal processing job to a sampled speech signal. I have already done the sampling to a speech signal and got the sampled 60001 values. The next step I am going to do is to normalise the sampled values,i.e. set the maximum value to +1 and the minimum value to -1. By using the function "wavread", the read in data has been put in the range of [-1,+1]. According to what I have found, the maximum value of the sampled 60001 values is 0.9920, while the minimum value is -1. So, my algorithm is to divide all the +ve values with 0.9920. Is it correct? I tried the following program: m = max(sv); % sv is the array containing the sampled 60001 values for k = 1:60001 % sv2 is another array I am going to store the if sv(k)>0 % normalised values. sv2(k) = sv(k)/m % if the element is +ve, divide it with m. else sv2(k) = sv(k) % if the element is 0 or +ve, keep it. end end When running the above, I found that it ran very slowly and I can see the data rolling on the screen of Command Window. Can anyone give me some advice on how to do the loop with C/C++ but using the compiler of MATLAB?
How about an instance of CChainSaw ? Regardz Colin J Davies
*** WARNING *
This could be addictive
**The minion's version of "Catch :bob: "It's a real shame that people as stupid as you can work out how to use a computer. said by Christian Graus in the Soapbox
-
:confused: I am going to do a signal processing job to a sampled speech signal. I have already done the sampling to a speech signal and got the sampled 60001 values. The next step I am going to do is to normalise the sampled values,i.e. set the maximum value to +1 and the minimum value to -1. By using the function "wavread", the read in data has been put in the range of [-1,+1]. According to what I have found, the maximum value of the sampled 60001 values is 0.9920, while the minimum value is -1. So, my algorithm is to divide all the +ve values with 0.9920. Is it correct? I tried the following program: m = max(sv); % sv is the array containing the sampled 60001 values for k = 1:60001 % sv2 is another array I am going to store the if sv(k)>0 % normalised values. sv2(k) = sv(k)/m % if the element is +ve, divide it with m. else sv2(k) = sv(k) % if the element is 0 or +ve, keep it. end end When running the above, I found that it ran very slowly and I can see the data rolling on the screen of Command Window. Can anyone give me some advice on how to do the loop with C/C++ but using the compiler of MATLAB?
I am in no way whatsoever a Matlab expert, but what I do remember from when I was using it a couple of years back is that for-loops are generally considered to be a big no-no if you want your code to execute quickly. If you can't replace the loop with something else (what you usually do to avoid using a for-loop is to perform one or more matrix operations instead), most often you simply have to accept the slowness or compile your code. At least that's what I learned back then.
-
:confused: I am going to do a signal processing job to a sampled speech signal. I have already done the sampling to a speech signal and got the sampled 60001 values. The next step I am going to do is to normalise the sampled values,i.e. set the maximum value to +1 and the minimum value to -1. By using the function "wavread", the read in data has been put in the range of [-1,+1]. According to what I have found, the maximum value of the sampled 60001 values is 0.9920, while the minimum value is -1. So, my algorithm is to divide all the +ve values with 0.9920. Is it correct? I tried the following program: m = max(sv); % sv is the array containing the sampled 60001 values for k = 1:60001 % sv2 is another array I am going to store the if sv(k)>0 % normalised values. sv2(k) = sv(k)/m % if the element is +ve, divide it with m. else sv2(k) = sv(k) % if the element is 0 or +ve, keep it. end end When running the above, I found that it ran very slowly and I can see the data rolling on the screen of Command Window. Can anyone give me some advice on how to do the loop with C/C++ but using the compiler of MATLAB?
1.) You really shouldn't be posting programming questions in the lounge. People get annoyed with that. 2.) To increase speed, there are two things you need to do. i.) Pre-initialize all your arrays. That is declare space for them at the start of the .m file ii.) put a semicolon at the end of each line for Pete's sake. Who taught you Matlab, man? To suppress output you always stick a semi-colon at the end of each line. It think that's lesson number zero or something - "The Zeroth Law of Matlab" :rolleyes: iii.) Alternatively you could tell me what the project is and then pay me to code it for you... :-D John Theal Physicist at Large Got CAD? http://www.presenter3d.com[^]