query regarding linspace
6 views (last 30 days)
Show older comments
the book code says
A = linspace(0, 0.9, (length(y)*0.2)); %rise 20% of signal
D = linspace(0.9, 0.8,(length(y)*0.05)); %drop of 5% of signal
S = linspace(0.8, 0.8,(length(y)*0.4)); %delay of 40% of signal
R = linspace(0.8, 0,(length(y)*0.35)); %drop of 35% of signal
y is a tone signal of music
if i change the first two values of linspace, there is no change in audio. what is purpose of linspace in this command
1 Comment
Walter Roberson
on 22 Sep 2011
You need to be careful: linspace() always includes the first and last values in the range, so if you put D right after A, you would have two 0.9 beside each other. Sometimes that is what you want, but usually it is not.
Accepted Answer
Wayne King
on 22 Sep 2011
Without more context, it's hard to say how they are using these vectors, but linspace() is just creating a linearly-spaced vector from A to B using the specified number of points. The spacing between points obviously depends on the starting and stopping points and the total number of samples (elements).
A = linspace(0,0.9,(length(y)*0.2));
Says "create a vector of linearly-spaced increments from 0 to 0.9 that is 20% of the length of y."
D = linspace(0.9, 0.8,(length(y)*0.05));
Create a vector that goes down from 0.9 to 0.8 using the number of points equal to 5% of the length of y.
S = linspace(0.8, 0.8,(length(y)*0.4));
The above is just a vector of the same value, 0.8, that is 40% of the length of y -- [0.8 0.8 0.8 .... ]
0 Comments
More Answers (6)
Wayne King
on 22 Sep 2011
You'll have to convert the cell arrays with cell2mat(), or you'll have to do something like this.
C = cell(2,1);
C{1} = randn(1e3,1);
tone = C{1}.*ones(1e3,1);
I personally recommend that you write your own little ASDR function that accepts a vector input, so you convert from a cell array to a vector outside the function or feed the function C{i} and then inside the function create your envelope and multiply your signal by it and then return your signal as the output.
Wayne King
on 22 Sep 2011
They have created this envelope with
fs=8500;
y=sin(2*pi*300*(0:0.000117:3));
A = linspace(0, .9, (length(y)*0.25)); %rise 20% of signal
D = linspace(.9, 0.7,(length(y)*0.05)); %drop of 5% of signal
S = linspace(0.7, 0.7,(length(y)*0.40)); %delay of 40% of signal
R = linspace(0.7, 0,(length(y)*0.30)); %drop of 35% of signal
ADSR = [A D S R] ;
Then they multiply the sine wave element by elementy by ADSR. The sine wave oscillates between [-1 1], but when you multiply it element by element by the ADSR envelope, the sine wave oscillates between positive and negative values within the shape of the envelope.
0 Comments
moonman
on 22 Sep 2011
1 Comment
Wayne King
on 22 Sep 2011
I'm glad you solved your problem and you're very (too) kind. There are many here who know far,far more than me and freely give so much of their time helping people. That's what makes the MATLAB user community so great. I'm amazed at the level of knowledge here, on the newsgroup, and the file exchange. And how generously they impart that knowledge to others.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!