how to apply Gaussian filter to imported data (two columns: x and y)

조회 수: 46 (최근 30일)
Tian Tian
Tian Tian 2017년 8월 3일
댓글: Kirti Gaur 2019년 5월 13일
Hi,
I am new to Matlab,and what i want to do is: import two columns of data (x and y) into Matlab, apply Gaussian filter on plot graph drawn from data, then find peaks of y data with corresponding x located. Now my problem is: when importing to Matlab, column labels of data got lost, so I couldn't use peak analysis on specified column; also, is there any way to apply Gaussian on plot graph?
Many thanks for your answer. Tian

답변 (2개)

Kris Fedorenko
Kris Fedorenko 2017년 8월 7일
Hi Tian!
I am not sure if I quite understood all of your question, but here is what I think you want to do:
  1. import two columns of data preserving the column names (x, y)
  2. plot the data
  3. apply Gaussian filter to smooth the data in y and plot it
  4. use the smoothed data to find local peaks in y and the corresponding x values
If I understood your question correctly, this simple example might be helpful:
%%1. import two columns of data preserving the column names (x, y)
% Assuming you have a .csv or an excel file with two numeric columns named x and y,
% you can use "readtable" to import your data
data = readtable('sample_data.csv')
% you can now access x values as data.x and y values as data.y
%%2. plot the data
figure;
plot(data.x, '*-') % plot x as stars
hold on;
plot(data.y, 'o-') % and y as circles
hold off;
%%3. apply Gaussian filter to smooth the data in y and plot it
% create filter
sigma = 10; % pick sigma value for the gaussian
gaussFilter = gausswin(6*sigma + 1)';
gaussFilter = gaussFilter / sum(gaussFilter); % normalize
filteredY = conv(data.y, gaussFilter, 'same');
% plot filtered y and original y to see the effect:
figure;
plot(data.y, 'o-r') % plot original y as cirlces
hold on;
plot(filteredY, 'b') % and filtered y as a solid line
hold off;
%%4. use the smoothed data to find local peaks in y and the corresponding x values
[peak_values, peak_indices] = findpeaks(filteredY);
% use peak's indices to find corresponding x values:
corresp_x = data.x(peak_indices)
Hope this helps!
Kris
  댓글 수: 5
Kris Fedorenko
Kris Fedorenko 2017년 8월 9일
Hi Tian!
I am still a bit unclear about your question, but sounds like you might be interested in fitting multiple gaussians to your data? In this case you might consider looking into the following documentation pages:
As for plotting your y data versus your x data, you can do it as follows:
plot(data.x, data.y)
Kirti Gaur
Kirti Gaur 2019년 5월 13일
how do i apply guided filter on csv file of hyperspectral dataset ! can anyone help me please as soon as possible .

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


abolfazl fardad
abolfazl fardad 2017년 12월 16일
Hi Kris,
Thank you for giving your codes. Would you please explain why you find gausswin for (6*sigma+1):
gaussFilter = gausswin(6*sigma + 1)';
Ned

카테고리

Help CenterFile Exchange에서 Measurements and Feature Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by