在y轴上绘制频域中的呼吸信号,同时在x轴上绘制时间

时间:2018-02-10 11:43:49

标签: matlab signal-processing fft

我有呼吸(呼吸)信号和25 Hz的采样频率,需要检测时间刻度上最低呼吸频率的位置,这应该告诉我实际上该人何时昏昏欲睡。经典形式的傅里叶变换并没有给我很多有用的信息。因此,澄清一下:测量时间应在x轴上,呼吸频率应在y轴上。然后,我想,较低的信号幅度将显示呼吸较慢。应该如何处理信号以我需要的方式绘制它?

1 个答案:

答案 0 :(得分:2)

此代码的所有学分均归Star Strider所有。

 D = load('respiratory.txt');
    Fs = 25;                                                    % Sampling Frequency (Hz)
    Fn = Fs/2;                                                  % Nyquist Frequency
    Ts = 1/Fs;                                                  % Sampling Time (sec)
    L = numel(D);
    t = linspace(0, L, L)*Ts;                                   % Time Vector (sec)

figure(1)
plot(t, D)
grid
% axis([0  60    -850  -750])
axis([xlim    -850  -750])
xlabel('Time')
ylabel('Amplitude')

FTD = fft(D-mean(D))/L;                                     % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn;                         % Frequency Vector
Iv = 1:numel(Fv);                                           % Index Vector

figure(2)
plot(Fv, abs(FTD(Iv))*2)
grid
axis([0  2.5    ylim])
xlabel('Frequency (Hz)')
ylabel('Amplitude')

Wp = [0.35 0.65]/Fn;                                        % Passband Frequency (Normalised)
Ws = [0.30 0.75]/Fn;                                        % Stopband Frequency (Normalised)
Rp =   1;                                                   % Passband Ripple (dB)
Rs =  50;                                                   % Stopband Ripple (dB)
[n,Ws]  = cheb2ord(Wp,Ws,Rp,Rs);                            % Filter Order
[z,p,k] = cheby2(n,Rs,Ws);                                  % Filter Design, Sepcify Bandpass
[sos,g] = zp2sos(z,p,k);                                    % Convert To Second-Order-Section For Stability

figure(3)
freqz(sos, 2^16, Fs)                                        % Filter Bode Plot

D_filtered = filtfilt(sos, g, D);                           % Filter Signal

[pks,locs] = findpeaks(D_filtered, 'MinPeakDist',40);

figure(4)
plot(t, D_filtered)
hold on
plot(t(locs), pks, '^r')
hold off
grid
% axis([0  60    ylim])
axis([0  60    -15  15])
xlabel('Time')
ylabel('Amplitude')

tdif = diff([0 t(locs)]);                                   % Time Difference Between Peaks (sec)
Dfrq = 60./tdif;                                            % Frequency (Respirations/Minute)

figure(5)
plot(t(locs), Dfrq)
grid
axis([xlim    10  40])
xlabel('Time (sec)')
ylabel('Frequency (minute^{-1})')