# Extract signal values from a data file

조회 수: 7 (최근 30일)
Hussein Kokash 2022년 12월 19일
댓글: Star Strider 2022년 12월 23일
Hello all,
I am trying to extract some basic signal values from a data file that I have which is a plot of a sinosodial wave vs length:
z = data(:,1);
y = data(:,2);
figure(1)
plot(z,y,'b')
xlabel('Spanwise length')
ylabel('Velocity')
I want to identify and match the following:
% Fs=800;
% Tf=2;
% t=0:1/Fs:Tf;
% f=[40 75];
% Amp=[4.5 9.22];
% sigma=1.33;
% y=Amp(1)*exp(j*2*pi*t*f(1))+Amp(2)*exp(j*2*pi*t*f(2));
% N=(sigma/sqrt(2))*(randn(size(t))+j*randn(size(t)));
% y=y+N;
% fy=FFT(y,Fs);
The above code is part of the code:
PSD (Power Spectral Density), and Amplitude Spectrum with adjusted FFT
I know that the length in my case is z, Can you guide me on how to identify the above values (Fs, Tf, f, Amp, N, etc..)?
The data file is attacehd, I appreciate your input.
Thanks!

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

### 채택된 답변

Star Strider 2022년 12월 19일
I am not certain what ‘identify and match’ means. It is certainly possible to filter the 40 and 75 Hz frequencies individually, and their both defining a bandwidth, with a bandpass filter (introduced in R2018a, so you should have it) —
z = data(:,1);
y = data(:,2);
Fs = 1/mean(diff(z))
Fs = 500
f=[40 75];
figure(1)
plot(z,y,'b')
xlabel('Spanwise length')
ylabel('Velocity')
Hz40 = bandpass(y, [-1 1]+f(1), Fs, 'ImpulseResponse','iir');
Hz75 = bandpass(y, [-1 1]+f(2), Fs, 'ImpulseResponse','iir');
Hz4075 = bandpass(y, f, Fs, 'ImpulseResponse','iir');
figure
subplot(3,1,1)
plot(z, Hz40)
grid
ylabel('Amplitude')
title('40 Hz')
subplot(3,1,2)
plot(z, Hz75)
grid
ylabel('Amplitude')
title('75 Hz')
subplot(3,1,3)
plot(z, Hz4075)
grid
xlabel('z')
ylabel('Amplitude')
title('40-75 Hz')
Experiment to get different results.
.
##### 댓글 수: 6이전 댓글 4개 표시이전 댓글 4개 숨기기
Hussein Kokash 2022년 12월 23일
Hello , sorry for the trouble,
I have used this code but extended it so that it covers a 2D plane of coordinates (x, y) with their velocities (U, V)
clear all; clc;%close all;
path = pwd; % put current path here
S = dir(fullfile(path,'data_*.txt'));
R = dir(fullfile(path,'data_*.txt'));
S = natsortfiles(R);
if iscell(S) == 0;
S = (S);
end
for k = 1:numel(S)
folder = S(k).folder;
filename = S(k).name;
F = fullfile(S(k).folder,S(k).name);
x = data(:,1); % x coordinate
y = data(:,2); % y coordinate
U(:,k) = data(:,4); % u velocity
V(:,k) = data(:,5); % v velocity
Fs(k) = 1/mean(diff(x));
figure(1)
pwelch(V)
[pxx,f,pxxc] = pwelch(V,[],[],[],Fs,'ConfidenceLevel',0.95);
fidx = ismembertol(f, [40 75], 0.01);
freqs = f(fidx);
PSDs = pxx(fidx);
PSDci = pxxc(fidx,:);
PSDTable = table(freqs,PSDs,PSDci)
PSDdBTable = table(freqs,pow2db(PSDs),pow2db(PSDci),'VariableNames',{'freqs','PSDs (dB)','PSDci (dB)'})
figure(2)
plot(f, pow2db(pxx), 'DisplayName','PSD')
hold on
plot(f, pow2db(pxxc), '--r', 'DisplayName','95% CI')
hold off
grid
xlabel('Frequency (Hz)')
ylabel('PSD (dB/Hz)')
legend('Location','best')
end
I am getting this error:
Error using table (line 307)
'PSDs (dB)' is not a valid variable name.
Error in testpwelch (line 36)
PSDdBTable = table(freqs,pow2db(PSDs),pow2db(PSDci),'VariableNames',{'freqs','PSDs (dB)','PSDci (dB)'})
Any thoughts?
Thanks!
Star Strider 2022년 12월 23일
As always, my pleasure!
The ability to use table variables that were not valid MATLAB variable names was introduced after R2018b. I forgot about that. Use: 'PSDs_dB' and such instead (or create your own variable names, since there is nothing particularly sacred about the ones I chose). Anything that is a valid MATLAB variable name should work.
PSDdBTable = table(freqs,pow2db(PSDs),pow2db(PSDci),'VariableNames',{'freqs','PSDs_dB','PSDci_dB'})
That should run without error.
.

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

### 카테고리

Help CenterFile Exchange에서 Spectral Estimation에 대해 자세히 알아보기

R2018b

### Community Treasure Hunt

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

Start Hunting!

Translated by