help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: peaks and valleys plot


From: Rick T
Subject: Re: peaks and valleys plot
Date: Fri, 30 Dec 2011 16:01:05 -1000

Thanks that worked ;-)

On Fri, Dec 30, 2011 at 3:42 PM, Ben Abbott <address@hidden> wrote:

On Dec 30, 2011, at 8:26 PM, Rick T wrote:

> On Fri, Dec 30, 2011 at 2:19 PM, Ben Abbott <address@hidden> wrote:
>> On Dec 30, 2011, at 7:08 PM, Rick T wrote:
>>
>> > Greetings All
>> >
>> > I'm trying to have the x value and y value next to the peak and valley on a plot can someone assist
>> >
>> > t= linspace(0,2*pi,8000);
>> > freq=10;
>> > y=sin(t*freq)+cos(t*freq*1.3);
>> > y=y';
>> > y2=y*3+y*4+y*2;
>> > yf=(y2(:,1)/max(abs(y2(:,1)))*1); %keep at 1, amplitude levels
>> > plot(yf)
>>
>> I haven't tested this.
>>
>> [~, mn] = min (yf);
>> [~, mx] = max (yf);
>> plot (t, yf, t(mn), yf(mn), "s", t(mx), yf(mx), "s")
>> text (t(mn), yf(mn), sprintf ("min = %f", yf(mn)), "verticalalignment", "top", "horizontalalighment", "center")
>> text (t(mx), yf(mx), sprintf ("max = %f", yf(mx)), "verticalalignment", "bottom", "horizontalalighment", "center")
>>
>> Ben
>
> thanks but it comes back with an error
>
> parse error near line 10 of file test_plot.m
> syntax error
> >>> [~, mn] = min (yf);
> ^
> >>>error: source: error sourcing file `test_plot.m'
>
> this was the code I used
>
> t= linspace(0,2*pi,8000);
> freq=10;
> y=sin(t*freq)+cos(t*freq*1.3);
> y=y';
> y2=y*3+y*4+y*2;
> yf=(y2(:,1)/max(abs(y2(:,1)))*1); %keep at 1, amplitude levels
> %plot(yf)
> [~, mn] = min (yf);
> [~, mx] = max (yf);
> plot (t, yf, t(mn), yf(mn), "s", t(mx), yf(mx), "s")
> text (t(mn), yf(mn), sprintf ("min = %f", yf(mn)), "verticalalignment", "top", "horizontalalighment", "center")
> text (t(mx), yf(mx), sprintf ("max = %f", yf(mx)), "verticalalignment", "bottom", "horizontalalighment", "center")

Ok. It looks like you are using an old version of Octave. The last release was 3.4.3 and 3.6.0 will be release soon.

To work with Octave-3.2.4 try the slightly modified script below.

y2=y*3+y*4+y*2;
yf=(y2(:,1)/max(abs(y2(:,1)))*0.9);
[jnk, mn] = min (yf);
[jnk, mx] = max (yf);
plot (t, yf, t(mn), yf(mn), "s", t(mx), yf(mx), "s")
text (t(mn), yf(mn), sprintf ("min = %f", yf(mn)), "verticalalignment", "top", "horizontalalignment", "center")
text (t(mx), yf(mx), sprintf ("max = %f", yf(mx)), "verticalalignment", "bottom", "horizontalalignment", "center")

I've attached a pdf of the result I get.

Ben











--


reply via email to

[Prev in Thread] Current Thread [Next in Thread]