Extract signal values from a data file

7 次查看(过去 30 天)
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:
data = dlmread('data_30.txt');
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
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) —
data = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1236212/data_30.txt');
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 个评论
Hussein Kokash
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'));
addpath('/media/hf9098/easystore/MATLAB/POD-umich')
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);
data = dlmread(F);
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
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.
Try this instead —
PSDdBTable = table(freqs,pow2db(PSDs),pow2db(PSDci),'VariableNames',{'freqs','PSDs_dB','PSDci_dB'})
That should run without error.
.

请先登录,再进行评论。

更多回答(0 个)

类别

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