信号分成图表上的部分

时间:2017-11-29 11:24:03

标签: matlab math charts fft physics

我有来自干涉仪的信号,然后通过FFT(快速傅立叶变换)进行滤波,滤波器本身可以正常工作。 现在我过滤我选择的范围内的信号,我也可以在整个范围内进行此操作,但我想将此信号切换成部件并过滤/分析每个部件,它可以自动完成,或者我可以进入我的范围想。为了削减这一点,我必须使用一些窗口?

该计划的截图:

enter image description here

enter image description here

指向所有文件的链接:hereherehere

我的代码:

clear all; 
close all; 
clc; 
file_name = 'W0009.dat';
[lam, I] = read_spectrum(file_name);
lam = lam*1e-3;
figure(1)
plot(lam,I, '-k');hold on;

mask = lam >= 1.6 & lam <= 1.8;
N = sum(mask);
w = hamming(N);

if mod(N, 2) == 0
    f = (-fix(N/2) : fix(N/2) - 1)/N; % czestotliwości dla N parzystego
else
    f = (-fix(N/2) : fix(N/2))/N; % czestotliwości  dla N nieparzystego
end

F = 2*fftshift(fft(I(mask)))/N;
W = fftshift(fft(I(mask).*w));

m = abs(f) <= 0.04;
F(not(m)) = 0;

figure(2)
semilogy(f, abs(F), '-k');hold on;
% semilogy(f, abs(W), '-r');hold on;

fI = -abs(N*ifft(fftshift(F))/2);
figure(3);
plot(lam(mask), I(mask), '-k');hold on;
plot(lam(mask), fI, '-r');

% M = 258; b = fir1(M, 0.45);
% I1 = I;
% I1 = filter(b, 1, I1); I1(1 : end - floor(M/2)) = I1(floor(M/2) + 1 : end);
% I1 = filtfilt(b, 1, I1);
% plot(lam,I1);hold on;
% 
% M = 38; b = fir1(M, 0.15);
% I2 = I;
% I2 = filter(b, 1, I2); I2(1 : end - floor(M/2)) = I2(floor(M/2) + 1 : end);
% I2 = filtfilt(b, 1, I2);
% plot(lam,I2);hold on;
% 
% M = 52; b = fir1(M, 0.05);
% I3 = I;
% I3 = filter(b, 1, I3); I3(1 : end - floor(M/2)) = I3(floor(M/2) + 1 : end);
% I3 = filtfilt(b, 1, I3);
% plot(lam,I3);hold on;
% 
% fm1 = lam < 1.8394 & lam > 1.5584;
% Ifinal1 = I1(fm1);
% fm2 = lam > 1.8394 & lam < 1.98138;
% Ifinal2 = I2(fm2);
% fm3 = lam < 2.216 & lam > 1.98138;
% Ifinal3 = I3(fm3);
% lamfinal = [lam(fm1);lam(fm2);lam(fm3)];
% Ifinal = [Ifinal1;Ifinal2;Ifinal3];
% close;
% figure(2)
% plot(lamfinal,Ifinal); hold on;
% 
% nlam = linspace(lamfinal(1), lamfinal(end), 9*length(lamfinal)).';
% nI = interp1(lamfinal, Ifinal, nlam, 'spline');
% plot(nlam,nI);
% 
% close;
% figure(3)
% [PKS1,LOCS1]= findpeaks(nI);
% plot(nlam,nI);hold on;
% plot(nlam(LOCS1),PKS1,'or'); hold on;
% [PKS2,LOCS2]= findpeaks(-nI,'MinPeakWidth',25);
% % PKS1 = [PKS1(1:73);PKS1(75:end)];
% % LOCS1 = [LOCS1(1:73);LOCS1(75:end)];
% % PKS2 = [PKS2(1:75);PKS2(77:end)];
% % LOCS2 = [LOCS2(1:75);LOCS2(77:end)];
% plot(nlam(LOCS2),-PKS2,'or');
% axis tight;

1 个答案:

答案 0 :(得分:0)

要分析三个参数范围,您可以先定义它们,然后在循环中处理它们

% Definition of ranges
ranges = [1.2,1.6 ; 1.6, 1.8 ; 1.8, 2.4];
% Number of ranges defined
nRanges = size(ranges,1);
% loop over ranges
for i=1:nRanges
  % ... some stuff from your program
  % Define the masking area
  mask = lam >= ranges(i,1) & lam <= ranges(i,2);
  % ... more stuff from your program
end

您应该能够以这种方式修改您的程序。