I'm having issues with using findpeaks() for lab data.
I have my script calling a csv file with 2 columbs of data.
As you can see from my script I can get the data to plot easily, however when I insert findpeaks(col1,col2) or findpeaks(data) I get an error message I don't understand.
The error I get is as follows:
----
Error using findpeaks
Expected Y to be a vector.
Error in findpeaks>parse_inputs (line 199)
validateattributes(Yin,{'double','single'},{'nonempty','real','vector'},...
Error in findpeaks (line 136)
= parse_inputs(isInMATLAB,Yin,varargin{:});
---
Can anyone please explaene to me why this isn't working.
clear all;
clc;
%Lab 2 Signoff 3
data=importdata("Light-Lab2.csv");
col1 = data(:,1);
col2 = data(:,2);
plot(col1,col2)
grid on, grid minor
title('lab2 data')
xlabel("Time")
ylabel("voltage")
findpeaks(data)
%findpeaks(col1,col2)

 채택된 답변

ME
ME 2020년 4월 28일

1 개 추천

I must stress that I am not sure and I don't have acces to the Signal Processing Toolbox to check. However, have you tried reversing the order of col1, col2 in your find peaks command?
I think that command is asking it to output the x-axis locations of the peaks in your y-axis data. This would be done as findpeaks(data,x). Therefore your x-data needs to be the second input argument and at present I think they are the wrong way around.
I think the issue when you try findpeaks(data) is that you aren't feeding in a vector (1xN) but rather an array (2xN).
I hope that helps!

댓글 수: 5

Right.
Try this:
findpeaks(col2)
or:
findpeaks(col2,col1)
Use the name-value pair arguments as necessary to get the desired result.
So I tried doing findpeaks(col2,col1) and I got a graph that had was very odd looking to me.
When I don't put in the findpeaks(col2,col1) that the graph is the first image (notice the x-axis).
When I do it's the 2nd image, the x-axis looks very different and I do not know why.
I've also tried using [len,pks]=findpeaks(col2,col1) and then plotting those.
It still looks strange and I really don't understand what's going on.
clear all;
clc;
%ME451 Lab 2 Signoff 3
data=importdata("Light-Lab2.csv");
col1 = data(:,1);
col2 = data(:,2);
plot(col1,col2)
grid on, grid minor
title('Lab 2 signoff 3 light data')
xlabel("Time")
ylabel("voltage")
%[len,pks]=findpeaks(col2,col1) %using this for a plot
%plot(len,pks)
%findpeaks(col2,col1) %from previous suggestion
% xlabel("Time")
% ylabel("voltage")
% title("Peaks")
%findpeaks(col2,'MinPeakDistance',2); %no lower arrows & no 2nd plot
Joshua Walters
Joshua Walters 2020년 4월 28일
Here's the strange graph I get with the [len,pks] plot
Update,
This ended up getting me, I think, what I needed:
clear all;
clc;
%ME451 Lab 2 Signoff 3
data=importdata("Light-Lab2.csv");
col1 = data(:,1)/1000;
col2 = data(:,2);
plot(col1,col2)
grid on, grid minor, hold on
title('Lab 2 signoff 3 light data')
xlabel("Time")
ylabel("voltage")
[pks,len]=findpeaks(col2,col1,'MinPeakHeight',1.5); %using this for a plot
plot(len,pks,'r*')
grid on, grid minor
%findpeaks(col2,col1) %from previous suggestion
xlabel("Time")
ylabel("voltage")
title("[Insert swear word here]")
%findpeaks(col2,'MinPeakDistance',2); %no lower arrows & no 2nd plot
time_s=length(col1)/32.66;
avg_freq=1/time_s;
fprintf('Average frequency = %6.2f Hz',avg_freq)
Thanks for your help :)
ME
ME 2020년 4월 28일
No problem, apologies I couldn’t be more help. Without access to the toolbox I couldn’t test anything out.
Anyway, if this helped you would you possibly consider accepting my answer?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Parametric Spectral Estimation에 대해 자세히 알아보기

질문:

2020년 4월 28일

댓글:

ME
2020년 4월 28일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by