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

  • SEARCH
  • Home
  • 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 6229773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:37:52+00:00 2026-05-24T09:37:52+00:00

fsamp = 2; deltaf = fsamp/nfft; % FFT resolution Nfreqtimestwo = 128; % Used

  • 0
fsamp = 2;
deltaf = fsamp/nfft;   % FFT resolution
Nfreqtimestwo = 128;  % Used below
Nsines = Nfreqtimestwo/2 - 1;   % Number of sine waves
fmult = [1:Nsines];  % multiplicative factor
freq_fund = fsamp/Nfreqtimestwo;
freq_sines = freq_fund.*fmult; 
omega = 2*pi*freq_sines;
r = int16(0);
for(ii=1:Nsines)
    r = r + cos((omega(ii)/fsamp)*(0:messageLen-1));   
end

This is the code I am currently using to create my input signal. However, the end result of r is a 32,768 array of doubles. Now I would like to do the best approximation of that using int16. However, I would like to note that amplitude doesn’t really matter. For example, my best approach so far I think has been:

    fsamp = 2;
    deltaf = fsamp/nfft;   % FFT resolution
    Nfreqtimestwo = 128;  % Used below
    Nsines = Nfreqtimestwo/2 - 1;   % Number of sine waves
    fmult = [1:Nsines];  % multiplicative factor
    freq_fund = fsamp/Nfreqtimestwo;
    freq_sines = freq_fund.*fmult; 
    omega = 2*pi*freq_sines;
    r = int16(0);
    for(ii=1:Nsines)
        r = r + int16(8192*cos((omega(ii)/fsamp)*(0:messageLen-1)));   
    end

Are there any better ways to approach this?

EDIT
The reason I want to convert the doubles to ints is because this list is being used in an embedded system and eventually going to a 16-bit DAC… no doubles allowed

  • 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-24T09:37:53+00:00Added an answer on May 24, 2026 at 9:37 am

    int16(vector) converts vector from double to int16 and this is the preferred way. The alternate way of doing it is to define all your constants as int16s in which case, MATLAB will give you the result as an int16. However, this is cumbersome, so stick with what you have (unless if you absolutely have to do it this way).

    Also, unrelated to your actual question, you can ditch the loop by using cumsum. I’ll leave that for you to try out 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a String that contains the following: ?workarea=London+&+Home+Counties+Ltd&sub=fs&&&FASh*5 which resembles a URI query
I'm working on a VB.NET to C# conversion and I'm currently stuck with a
I have this VB code that I am converting for someone, but he didn't
I have HTML I am generating in my app. I know it's valid because
I have this code, which is supposed to attach a HTML file to the

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.