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 1007329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:36:07+00:00 2026-05-16T08:36:07+00:00

I am looking to create a function that could create a fade-in/fade-out function on

  • 0

I am looking to create a function that could create a fade-in/fade-out function on a .wav file over a period of five seconds.

I found this code on the MATLAB forums but it seems the implementation was slightly wrong, although the right idea is there. It was for .WAV files of 300ms with a 10ms fade-in/out:

tenmssamples = length(soundfile)*10/300;
fade1 = linspace(0,1,tenmssamples);
fadedsound = soundfile .* ...
  [fade1, ones(1,length(soundfile)-2*tenmssamples), fliplr(fade1)];


tenmssamples = length(soundfile)*10/300;
fade2 = sin(linspace(0,2*pi/4,tenmssamples));
fadedsound2 = soundfile .* ...
  [fade2, ones(1,length(soundfile)-2*tenmssamples), fliplr(fade2)];

I can see what he was trying to do by trying to scale the first 10 samples of the waveform read by an increasing function using linspace, but I have tried to tinker and modify it but I cannot get it to work.

Does anyone have any suggestions please? Thank you.

  • 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-16T08:36:07+00:00Added an answer on May 16, 2026 at 8:36 am

    I’m not sure what the problem you are encountering is, but I would do something like this:

    Fs = 1000; % sampling rate of signal
    FADE_LEN = 5; % 5 second fade
    
    sig = randn(15.*Fs,1); % generate 15 s signal
    
    fade_samples = round(FADE_LEN.*Fs); % figure out how many samples fade is over
    fade_scale = linspace(0,1,fade_samples)'; % create fade
    
    sig_faded = sig;
    sig_faded(1:fade_samples) = sig(1:fade_samples).*fade_scale; % apply fade
    
    subplot(211)
    plot(sig)
    subplot(212)
    plot(sig_faded)
    

    of course you can replace the linspace by something else like a sigmoid, and use the same idea to do a fade out…

    EDIT: to do the fade out, try

    sig_faded(end-fade_samples+1:end) = sig(end-fade_samples+1:end).*fade_scale(end:-1:1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking to create a function that could toggle the ability to recurse
I'm looking to create a PHP function that can trim each line in a
I am looking to create a JavaScript function that will display a confirmation popup
I'm looking for a way to create a function that can be used in
I am looking for a function to create a so called Beeswarm boxplot. This
I'm looking to create a function that will return every possible string within a
I was looking for a way to create modules that could easily be included
I need some help figuring this out. I am trying to create a function
I'm looking for the optimal way to create a function that can accept no
I looking to create a custom calender with Zend Framework, I am hoping that

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.