Dear Members,(adsbygoogle = window.adsbygoogle || []).push({});

I am trying to apply a windowing function to a group of notes that I have created in MATLAB.

For example, a piecewise linear function that looks like this:

[img=http://img168.imageshack.us/img168/2058/adsrenvelopepg0.th.jpg]

(No specific slopes defined).

%I first define the sampling frequency.

Fs = 8000;

%Define n.

n1 = [0:(1/Fs):(1/2)]

n2 = [0:(1/Fs):(1/4)]

n3 = [0:(1/Fs):(1)]

%Create the notes.

note1 = sin(2*pi*220*n1);

note2 = sin(2*pi*220*n2);

note3 = sin(2*pi*(220*(2^(7/12))*n2);

note3 = sin(2*pi*(220*(2^(7/12)))*n2);

note4 = sin(2*pi*(220*(2^(2/12)))*n2);

note5 = sin(2*pi*(220*(2^(3/12)))*n2);

note6 = sin(2*pi*220*n3);

%Generate 0.25 second rest.

rest = zeros(1,(Fs/4));

%Generate song.

song = [note1 rest note2 rest note3 rest note3 rest note3 rest note4 rest note5 rest note4 rest note6 rest];

This part works... and the song is heard with the appropriate rest.

Now, if I want to apply an ADSR envelope to a note, I tried this:

A = linspace(0, 1, 0.1*(Fs));

D = linspace(1, 0.8, 0.15*(Fs));

S = linspace(0.8, 0.8, 0.6*(Fs));

R = linspace(0.8, 0, 0.15*(Fs));

%I then concatenate

ADSR = [A D S R];

%Then I try applying the envelope to a note

newnote1 = ADSR .* note1;

But I am given an error saying the Matrix dimensions do not agree. Does anyone happen to know how I can fix this problem? I am rather new to Matlab in general so I am having difficulty using any other command to properly apply the ADSR envelope with the note.

Thank you kindly in advance for your response.

**Physics Forums - The Fusion of Science and Community**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Using an ADSR Envelope in MATLAB

Loading...

Similar Threads - Using ADSR Envelope | Date |
---|---|

Using Maxima to plot error in Fourier series | Nov 5, 2017 |

Matlab Solving equation with integration using MATLAB | Aug 4, 2017 |

What Software do you use to do your math manipulations? | May 21, 2017 |

Mathematica plot envelope data smoothing | Jan 12, 2011 |

**Physics Forums - The Fusion of Science and Community**