0% found this document useful (0 votes)
27 views

Ex 1

This document contains code to fade an audio signal over time. It defines a fade function that takes in an audio vector x and a level parameter between 0 and 1. The function creates a ramp vector from 0 to 1 over the length of x and multiplies the audio by 1 minus the ramp scaled by level, fading the audio out over its duration. The code provides an example that generates a cosine wave, calls the fade function with a user-input level of 0.5, and plots the faded output.

Uploaded by

Bach Trung
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Ex 1

This document contains code to fade an audio signal over time. It defines a fade function that takes in an audio vector x and a level parameter between 0 and 1. The function creates a ramp vector from 0 to 1 over the length of x and multiplies the audio by 1 minus the ramp scaled by level, fading the audio out over its duration. The code provides an example that generates a cosine wave, calls the fade function with a user-input level of 0.5, and plots the faded output.

Uploaded by

Bach Trung
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Ex1:

>> time = 0:.01:1; y = cos(time .* pi .* 25); level=input('nhap vao he so suy giam l=') plot(time, fade(y,level));

function [ y ] = fade(x, level)


% fade(x): this function fades the audio vector x. % create the ramp vector t = linspace(0, 1, length(x)); % multiply the audio vector with the ramp vector to fade y = (1 - level.*(t)) .* x;

demo
>> time = 0:.01:1; y = cos(time .* pi .* 25); level=input('nhap vao he so suy giam l=') plot(time, fade(y,level)); nhap vao he so suy giam l=0.5

level =

0.5000

>>

1 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

You might also like