Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4234154
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:18:50+00:00 2026-05-21T02:18:50+00:00

I have an array of bits, such as the one below, and I need

  • 0

I have an array of bits, such as the one below, and I need to put a carrier wave on top of them. The question is: Is this possible to do without looping?

For example, suppose you are using Frequency-Shift-Keying. If the bit is a “1” then the signal should be a sine wave with a frequency of 10,000 Hz, and if the bit is a “0” then the signal should be a sine wave with a frequency of 8,000 Hz.

Bit-Array:

bits = [0 0 0 1 0 1 1 0 1 0 1 0 1 0 1 0 1]

Looping Code:

for i = 1:length(bits)
   if bits(i) == 1
      signal = [signal sin(2*pi*10000*t)]
   else
      signal = [signal sin(2*pi*8000*t)]
   end    
end

It would be nice if I could perform this all in a single operation with no looping.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T02:18:50+00:00Added an answer on May 21, 2026 at 2:18 am

    If t is a scalar, then you can replace your for loop with a single-line vectorized solution:

    signal = sin(2*pi*t.*(8000+2000.*bits));
    

    However, if you’re doing frequency-shift keying, it seems like you should be expanding each 0 or 1 in your bits vector into a sine wave with a given duration and frequency. For example, to create a modulated signal with 4 sine periods (0.1 msec) at 8 kHz for each 0 and 5 sine periods (0.1 msec) at 10 kHz for each 1, you can use the function KRON like so:

    t = 0:5e-6:4.95e-4;
    signal = sin(2*pi.*(kron(bits,10000.*t)+kron(~bits,8000.*t)));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array in Perl: my @my_array = (one,two,three,two,three); How do I remove
I have an array of shorts (short[]) that I need to write out to
I have a string representing bits, such as: 0000101000010000 I want to convert it
Background: I have a large 2D array of integers that I need to load
I have pcm audio stored in a byte array. It is 16 bits per
I have an array of numbers that potentially have up to 8 decimal places
I have an array of a few million numbers. double* const data = new
I have an array of items that are time sensitive. After an amount of
I have an array of hashes, and I want the unique values out of
I have an array of 1000 strings to load into a combo box. What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.