How do I downsample a signal using Octave?











up vote
1
down vote

favorite












I have been trying to downsample a signal, but I'm not sure if I have the proper command? can you give me the proper command with a brief explanation?










share|improve this question







New contributor




Mary ProgrammerWant2Be is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    Try the resample function from the signal package: octave.sourceforge.io/signal/function/resample.html
    – am304
    Nov 19 at 13:03















up vote
1
down vote

favorite












I have been trying to downsample a signal, but I'm not sure if I have the proper command? can you give me the proper command with a brief explanation?










share|improve this question







New contributor




Mary ProgrammerWant2Be is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    Try the resample function from the signal package: octave.sourceforge.io/signal/function/resample.html
    – am304
    Nov 19 at 13:03













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have been trying to downsample a signal, but I'm not sure if I have the proper command? can you give me the proper command with a brief explanation?










share|improve this question







New contributor




Mary ProgrammerWant2Be is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have been trying to downsample a signal, but I'm not sure if I have the proper command? can you give me the proper command with a brief explanation?







matlab octave






share|improve this question







New contributor




Mary ProgrammerWant2Be is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Mary ProgrammerWant2Be is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Mary ProgrammerWant2Be is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 19 at 12:48









Mary ProgrammerWant2Be

85




85




New contributor




Mary ProgrammerWant2Be is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Mary ProgrammerWant2Be is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Mary ProgrammerWant2Be is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1




    Try the resample function from the signal package: octave.sourceforge.io/signal/function/resample.html
    – am304
    Nov 19 at 13:03














  • 1




    Try the resample function from the signal package: octave.sourceforge.io/signal/function/resample.html
    – am304
    Nov 19 at 13:03








1




1




Try the resample function from the signal package: octave.sourceforge.io/signal/function/resample.html
– am304
Nov 19 at 13:03




Try the resample function from the signal package: octave.sourceforge.io/signal/function/resample.html
– am304
Nov 19 at 13:03












2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










Depending on what you are trying to achieve, the downsample can be enough.



Example code:



pkg load signal % To download the signal package
x = cos(1:1000); % Create a signal
y = downsample(x, 2);


However, it will not apply a low-pass filter so it can introduce unwanted aliasing effects on your signal. Like the command help downsample says:




For most signals you will want to use decimate instead since it prefilters the high frequency components of the signal and avoids aliasing effects.






Now if you want to downsample and apply the low-pass filter, you would like to use decimate but it only works for a downsampling with an integer factor, for example from 96kHz to 48kHz, you decimate by a factor 2. From help decimate




Note that Q must be an integer for this rate change method.




Example code:



pkg load signal % To download the signal package
x = cos(1:1000); % Create a signal
y = decimate(x, 2);




Finally, if you want to downsample by a rational number, for example by a factor of 2/3, from 96kHz to 64kHz, you will need resample like it was suggested by other users.



pkg load signal % To download the signal package
x = cos(1:1000); % Create a signal
y = resample(x, 2, 3);


Note that you can still use resample to downsample by an integer factor, for example y = resample(x, 1, 2); but it slower that decimate.






share|improve this answer






























    up vote
    0
    down vote













    e.g.



    y=resample(x,L,M);


    .



    .



    x--> your signal



    L--> increase sampling rate



    M--> reduce sampling rate






    share|improve this answer








    New contributor




    Nima is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.


















    • do I have to declare L and M or is it just apart of the code?
      – Mary ProgrammerWant2Be
      Nov 19 at 16:12











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    Mary ProgrammerWant2Be is a new contributor. Be nice, and check out our Code of Conduct.










     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375003%2fhow-do-i-downsample-a-signal-using-octave%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    Depending on what you are trying to achieve, the downsample can be enough.



    Example code:



    pkg load signal % To download the signal package
    x = cos(1:1000); % Create a signal
    y = downsample(x, 2);


    However, it will not apply a low-pass filter so it can introduce unwanted aliasing effects on your signal. Like the command help downsample says:




    For most signals you will want to use decimate instead since it prefilters the high frequency components of the signal and avoids aliasing effects.






    Now if you want to downsample and apply the low-pass filter, you would like to use decimate but it only works for a downsampling with an integer factor, for example from 96kHz to 48kHz, you decimate by a factor 2. From help decimate




    Note that Q must be an integer for this rate change method.




    Example code:



    pkg load signal % To download the signal package
    x = cos(1:1000); % Create a signal
    y = decimate(x, 2);




    Finally, if you want to downsample by a rational number, for example by a factor of 2/3, from 96kHz to 64kHz, you will need resample like it was suggested by other users.



    pkg load signal % To download the signal package
    x = cos(1:1000); % Create a signal
    y = resample(x, 2, 3);


    Note that you can still use resample to downsample by an integer factor, for example y = resample(x, 1, 2); but it slower that decimate.






    share|improve this answer



























      up vote
      2
      down vote



      accepted










      Depending on what you are trying to achieve, the downsample can be enough.



      Example code:



      pkg load signal % To download the signal package
      x = cos(1:1000); % Create a signal
      y = downsample(x, 2);


      However, it will not apply a low-pass filter so it can introduce unwanted aliasing effects on your signal. Like the command help downsample says:




      For most signals you will want to use decimate instead since it prefilters the high frequency components of the signal and avoids aliasing effects.






      Now if you want to downsample and apply the low-pass filter, you would like to use decimate but it only works for a downsampling with an integer factor, for example from 96kHz to 48kHz, you decimate by a factor 2. From help decimate




      Note that Q must be an integer for this rate change method.




      Example code:



      pkg load signal % To download the signal package
      x = cos(1:1000); % Create a signal
      y = decimate(x, 2);




      Finally, if you want to downsample by a rational number, for example by a factor of 2/3, from 96kHz to 64kHz, you will need resample like it was suggested by other users.



      pkg load signal % To download the signal package
      x = cos(1:1000); % Create a signal
      y = resample(x, 2, 3);


      Note that you can still use resample to downsample by an integer factor, for example y = resample(x, 1, 2); but it slower that decimate.






      share|improve this answer

























        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        Depending on what you are trying to achieve, the downsample can be enough.



        Example code:



        pkg load signal % To download the signal package
        x = cos(1:1000); % Create a signal
        y = downsample(x, 2);


        However, it will not apply a low-pass filter so it can introduce unwanted aliasing effects on your signal. Like the command help downsample says:




        For most signals you will want to use decimate instead since it prefilters the high frequency components of the signal and avoids aliasing effects.






        Now if you want to downsample and apply the low-pass filter, you would like to use decimate but it only works for a downsampling with an integer factor, for example from 96kHz to 48kHz, you decimate by a factor 2. From help decimate




        Note that Q must be an integer for this rate change method.




        Example code:



        pkg load signal % To download the signal package
        x = cos(1:1000); % Create a signal
        y = decimate(x, 2);




        Finally, if you want to downsample by a rational number, for example by a factor of 2/3, from 96kHz to 64kHz, you will need resample like it was suggested by other users.



        pkg load signal % To download the signal package
        x = cos(1:1000); % Create a signal
        y = resample(x, 2, 3);


        Note that you can still use resample to downsample by an integer factor, for example y = resample(x, 1, 2); but it slower that decimate.






        share|improve this answer














        Depending on what you are trying to achieve, the downsample can be enough.



        Example code:



        pkg load signal % To download the signal package
        x = cos(1:1000); % Create a signal
        y = downsample(x, 2);


        However, it will not apply a low-pass filter so it can introduce unwanted aliasing effects on your signal. Like the command help downsample says:




        For most signals you will want to use decimate instead since it prefilters the high frequency components of the signal and avoids aliasing effects.






        Now if you want to downsample and apply the low-pass filter, you would like to use decimate but it only works for a downsampling with an integer factor, for example from 96kHz to 48kHz, you decimate by a factor 2. From help decimate




        Note that Q must be an integer for this rate change method.




        Example code:



        pkg load signal % To download the signal package
        x = cos(1:1000); % Create a signal
        y = decimate(x, 2);




        Finally, if you want to downsample by a rational number, for example by a factor of 2/3, from 96kHz to 64kHz, you will need resample like it was suggested by other users.



        pkg load signal % To download the signal package
        x = cos(1:1000); % Create a signal
        y = resample(x, 2, 3);


        Note that you can still use resample to downsample by an integer factor, for example y = resample(x, 1, 2); but it slower that decimate.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 21 at 15:31

























        answered Nov 21 at 13:23









        Bebs

        6412923




        6412923
























            up vote
            0
            down vote













            e.g.



            y=resample(x,L,M);


            .



            .



            x--> your signal



            L--> increase sampling rate



            M--> reduce sampling rate






            share|improve this answer








            New contributor




            Nima is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.


















            • do I have to declare L and M or is it just apart of the code?
              – Mary ProgrammerWant2Be
              Nov 19 at 16:12















            up vote
            0
            down vote













            e.g.



            y=resample(x,L,M);


            .



            .



            x--> your signal



            L--> increase sampling rate



            M--> reduce sampling rate






            share|improve this answer








            New contributor




            Nima is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.


















            • do I have to declare L and M or is it just apart of the code?
              – Mary ProgrammerWant2Be
              Nov 19 at 16:12













            up vote
            0
            down vote










            up vote
            0
            down vote









            e.g.



            y=resample(x,L,M);


            .



            .



            x--> your signal



            L--> increase sampling rate



            M--> reduce sampling rate






            share|improve this answer








            New contributor




            Nima is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            e.g.



            y=resample(x,L,M);


            .



            .



            x--> your signal



            L--> increase sampling rate



            M--> reduce sampling rate







            share|improve this answer








            New contributor




            Nima is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            share|improve this answer



            share|improve this answer






            New contributor




            Nima is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            answered Nov 19 at 15:59









            Nima

            1




            1




            New contributor




            Nima is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





            New contributor





            Nima is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.






            Nima is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.












            • do I have to declare L and M or is it just apart of the code?
              – Mary ProgrammerWant2Be
              Nov 19 at 16:12


















            • do I have to declare L and M or is it just apart of the code?
              – Mary ProgrammerWant2Be
              Nov 19 at 16:12
















            do I have to declare L and M or is it just apart of the code?
            – Mary ProgrammerWant2Be
            Nov 19 at 16:12




            do I have to declare L and M or is it just apart of the code?
            – Mary ProgrammerWant2Be
            Nov 19 at 16:12










            Mary ProgrammerWant2Be is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            Mary ProgrammerWant2Be is a new contributor. Be nice, and check out our Code of Conduct.













            Mary ProgrammerWant2Be is a new contributor. Be nice, and check out our Code of Conduct.












            Mary ProgrammerWant2Be is a new contributor. Be nice, and check out our Code of Conduct.















             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375003%2fhow-do-i-downsample-a-signal-using-octave%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'