how to find fwhm using fwhm()?

I have a time domain data and also a FFT of this data. But when I use fwhm(x,y) then it says
Pulse Polarity = Positive
Pulse is Impulse or Rectangular with 2 edges
ans =
NaN
I am trying to also use findpeaks() but I don't know how to proceed after that. Any help would be appreciated. Thanks
Since the data is larger than 5 MB, I have attached the link to the data. Thanks,
There are 4 signals in the data and the first row is the frequency. I get the fwhm of only 2nd and 4th signals. Others show NaN. But the ones that I get are too incorrect as getting 4e3 and 4e7, which doesn't make sense. I have a nice FFT as attached below.

1 Comment

I am working on something similar, what do " polarity" and "is impulse or rectangular with 2 edges" mean?

Sign in to comment.

 Accepted Answer

Star Strider
Star Strider on 10 Oct 2020
The fwhm function is a File Exchange contribution. As I read the function code, it should likely give you something other than NaN if it detects 2 edges, however I have no idea what youare passing to it.
If you have the Signal Processing Toolbox, another option would be the findpeaks function. It will return the FWHM of the peaks it identifies if you ask it to. See the documentation for it that I linked to for details.

8 Comments

Hello, Thanks for your reply, I have updated the question with the dataset. Please see it again.
The file has 5 columns, the first appearing to be a time variable, What of the others are you interested in analysing? (Downloading it crashed my computer for some reason.)
Sorry for that. But the first column is not the time, but frequency. When you plot that with the following code then you should see the curve whose image I attached above.
%Prompt user for filename
[fname, pname] = uigetfile('*.csv');
%Create fully-formed filename as a string
filename = fullfile(pname, fname);
%Check that file exists
assert(exist(filename,'file')==2, '%s does not exist.', filename);
%Read in the data, skipping the first row
data = csvread(filename,1,0);
%%
figure('Position', [1 1 4000 700])
plot(data(:,1),data(:,2),'color', [1,0.55,0],'LineWidth',7);
hold on
plot(data(:,1),data(:,3),'color', [0,0.5,0],'LineWidth',7);
% hold on
% plot(data(:,1),data(:,4),'color', [0.9290, 0.6940, 0.1250],'LineWidth',1);
% hold on
% plot(data(:,1),data(:,5),'color', [0.75, 0, 0.75] ,'LineWidth',1);
axis([2500 6500 -65 2])
xticks([3000 4000 5000 6000])
xticklabels({'3','4','5','6'})
yticks([-70 -50 -30 -10 10])
yticklabels({'-70','-50','-30', '-10', '10'})
% legend('Oscillator A', 'Oscillator A', 'FontSize',48,'TextColor','black');
% legend('boxoff')
% legend('Orientation','horizontal')
% legend('Location','north')
a = get(gca,'XTickLabel');
% set(gca, 'XTickMode', 'auto', 'XTickLabelMode', 'auto')
set(gca,'XTickLabel',a,'fontsize',48,'FontWeight','normal')
Try this:
M1 = readmatrix('1.csv');
figure
plot(M1(:,1), M1(:,2:end))
grid
for k = 2:size(M1,2)
[pks{k-1}, locs{k-1}, fwhm{k-1}, prom{k-1}] = findpeaks(M1(:,k), 'MinPeakProminence', 55);
end
sbplts = size(M1,2);
figure
for k = 1:sbplts-1
subplot(sbplts-1,1,k)
plot(M1(:,1), M1(:,k+1))
hold on
plot(M1(locs{k},1), pks{k}, '^r')
hold off
end
for k1 = 1:4
fprintf(1,'Column %d\n',k1)
fprintf(1, '\t\tFreq = %8.3E\t\tPeak = %6.4f\t\tFWHM = %7.3f\n', [M1(locs{k1}), pks{k1}, prom{k1}]')
end
This produces essentially unreadable plots and:
Column 1
Freq = 8.896E+06 Peak = -58.6199 FWHM = 61.380
Freq = 4.995E+07 Peak = -63.6154 FWHM = 56.385
Column 2
Freq = 1.915E+04 Peak = -24.6881 FWHM = 65.306
Freq = 3.450E+04 Peak = -33.4822 FWHM = 56.968
Freq = 4.600E+04 Peak = -41.4325 FWHM = 67.335
Freq = 6.135E+04 Peak = -47.8441 FWHM = 62.809
Freq = 8.896E+06 Peak = -62.1915 FWHM = 57.808
Freq = 2.769E+07 Peak = -64.3326 FWHM = 55.667
Freq = 4.231E+07 Peak = -63.5646 FWHM = 56.435
Freq = 4.569E+07 Peak = -58.5343 FWHM = 61.466
Freq = 4.999E+07 Peak = -55.4661 FWHM = 57.035
Column 3
Freq = 2.300E+04 Peak = -25.8006 FWHM = 58.825
Freq = 2.474E+06 Peak = -64.5053 FWHM = 55.495
Column 4
Freq = 4.231E+07 Peak = -64.4779 FWHM = 55.522
That is the best I can do.
Experiment with it to get different results.
.
Wow, this worked. Thanks a lot. That is exactly what I needed. Just one small question, the peaks that it senses does not always include the first peak. The first peak is the only peak that I need. Like for example, in the data above that you sent, the fundamental frequency seems to be not getting recorded for all the columns. The 4 column data is perfectly frequency locked if you see their FFT. But, column 4 sees 4e7 as the fundamental frequency which is far far greater than the actual.
Another example, I tried this with another data I attach here. This shows that how it finds the first peak in one signal but fails to find the first peak in the other. Do you have any suggestions about the same?
As always, my pleasure!
Since you only need the first peak, try this:
M1 = readmatrix('1.csv');
figure
plot(M1(:,1), M1(:,2:end))
grid
for k = 2:size(M1,2)
[pks{k-1}, locs{k-1}, fwhm{k-1}, prom{k-1}] = findpeaks(M1(:,k), 'MinPeakProminence', 30, 'NPeaks',1);
end
sbplts = size(M1,2);
figure
for k = 1:sbplts-1
subplot(sbplts-1,1,k)
plot(M1(:,1), M1(:,k+1))
hold on
plot(M1(locs{k},1), pks{k}, '^r')
hold off
axis([0 5.7E3 -60 15])
grid
end
for k1 = 1:4
fprintf(1,'Column %d\n',k1+1)
fprintf(1, '\t\tFreq = %8.3E\t\tPeak = %6.4f\t\tFWHM = %7.3f\n', [M1(locs{k1}), pks{k1}, fwhm{k1}]')
end
producing:
Column 2
Freq = 3.850E+03 Peak = 0.0000 FWHM = 10.369
Column 3
Freq = 3.850E+03 Peak = 0.0000 FWHM = 8.304
Column 4
Freq = 3.850E+03 Peak = 0.0000 FWHM = 13.765
Column 5
Freq = 3.850E+03 Peak = 0.0000 FWHM = 13.337
and the appropriate plot.
My previous code printed the prominence values rather than the width values (it’s been a long day). This version corrects that, and prints the FWHM values.
The peak amplitude values of 0 are apparently appropriate, since the magnitude values appear to be in decibels. The column labels are corrected from my earlier post, since the frequencies are in Column 1, so the other columns (2:4) are the signal data.
.
This is great, and what I exactly needed.
Also, Can you tell me how can I find the phase noise of this data in dBc/Hz? I have made another post for this.
As always, my pleasure!
With respect to your other Question, I do not have the necessary blockset. That aside, I posted a ‘sort of’ Answer that is my best guess as to how to emulate it. That is the best I can do. I will delete that Asnwer if it is not what you want.

Sign in to comment.

More Answers (0)

Products

Release

R2020b

Tags

Asked:

on 10 Oct 2020

Commented:

on 17 Feb 2021

Community Treasure Hunt

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

Start Hunting!