Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. How to solve a loop problem with MATLAB?

How to solve a loop problem with MATLAB?

Scheduled Pinned Locked Moved The Lounge
c++algorithmsdata-structureshelptutorial
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qhm
    wrote on last edited by
    #1

    :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?

    N R C L 7 5 Replies Last reply
    0
    • Q qhm

      :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?

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      qhm wrote: Can anyone give me some advice on how to do the loop with C/C++ but using the compiler of MATLAB? Sure, try posting in the C++ forum[^] ;) - Nick Parker
        My Blog

      1 Reply Last reply
      0
      • Q qhm

        :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?

        R Offline
        R Offline
        Ryan Binns
        wrote on last edited by
        #3

        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"

        1 Reply Last reply
        0
        • Q qhm

          :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?

          C Offline
          C Offline
          ColinDavies
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • Q qhm

            :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?

            L Offline
            L Offline
            Lars Lundstedt
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • Q qhm

              :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?

              7 Offline
              7 Offline
              73Zeppelin
              wrote on last edited by
              #6

              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[^]

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups