
回复
% Define Sampling Frequency and Time Vector
fs = 1000; % Sampling frequency in Hz
duration = 5; % Duration of signal in seconds
t = 0:1/fs:duration-1/fs; % Time vector
% Simulate Normal and Pathological VAG Signals
vag_normal = sin(2*pi*50*t) + 0.2*randn(size(t)); % Normal VAG: 50 Hz with noise
vag_pathology = sin(2*pi*50*t) + 1.0*sin(2*pi*120*t) + 0.7*randn(size(t)); % Pathological: 50 Hz + 120 Hz with increased amplitude
% Bandpass Filter Design (20-250 Hz)
[b, a] = butter(3, [20 250]/(fs/2), 'bandpass'); % 3rd order Butterworth bandpass filter
% Apply Bandpass Filter
vag_normal_filtered = filtfilt(b, a, vag_normal); % Filter normal signal
vag_pathology_filtered = filtfilt(b, a, vag_pathology); % Filter pathological signal
% Detect Peaks in Filtered Signals
% Adjust parameters to detect more peaks in pathological signal
[peaks_normal, locs_normal] = findpeaks(vag_normal_filtered, 'MinPeakHeight', 0.5, 'MinPeakDistance', fs/20);
[peaks_pathology, locs_pathology] = findpeaks(vag_pathology_filtered, 'MinPeakHeight', 0.3, 'MinPeakDistance', fs/50); % Lower height, closer peaks
% Define Abnormality Detection Threshold
peak_threshold = 30; % Number of peaks threshold for abnormal detection
% Abnormality Detection Logic (Based on Filtered Signals)
is_abnormal_normal = length(peaks_normal) > peak_threshold; % True if abnormal
is_abnormal_pathology = length(peaks_pathology) > peak_threshold; % True if abnormal
% Generate Abnormality Status Strings
normal_status = 'No Detection'; % Default for normal signal
if is_abnormal_normal
normal_status = 'Yes Detection';
end
pathological_status = 'No Detection'; % Default for pathological signal
if is_abnormal_pathology
pathological_status = 'Yes Detection';
end
% Visualization
figure('Name', 'Knee Joint VAG Signal Analysis', 'NumberTitle', 'off');
% Plot 1: Original Normal Signal
subplot(4, 2, 1);
plot(t, vag_normal);
xlabel('Time (s)');
ylabel('Amplitude');
title('Original Normal VAG Signal');
grid on;
% Plot 2: Original Pathological Signal
subplot(4, 2, 2);
plot(t, vag_pathology);
xlabel('Time (s)');
ylabel('Amplitude');
title('Original Pathological VAG Signal');
grid on;
% Plot 3: Filtered Normal Signal with Detected Peaks
subplot(4, 2, 3);
plot(t, vag_normal_filtered);
hold on;
plot(locs_normal/fs, peaks_normal, 'ro'); % Mark peaks
xlabel('Time (s)');
ylabel('Amplitude');
title('Filtered Normal VAG Signal with Peaks');
grid on;
% Plot 4: Filtered Pathological Signal with Detected Peaks
subplot(4, 2, 4);
plot(t, vag_pathology_filtered);
hold on;
plot(locs_pathology/fs, peaks_pathology, 'ro'); % Mark peaks
xlabel('Time (s)');
ylabel('Amplitude');
title('Filtered Pathological VAG Signal with Peaks');
grid on;
% Plot 5: Spectrogram of Filtered Normal Signal
subplot(4, 2, 5);
spectrogram(vag_normal_filtered, 256, 200, 512, fs, 'yaxis');
title('Spectrogram of Filtered Normal VAG Signal');
xlabel('Time (s)');
ylabel('Frequency (Hz)');
colorbar;
% Plot 6: Spectrogram of Filtered Pathological Signal
subplot(4, 2, 6);
spectrogram(vag_pathology_filtered, 256, 200, 512, fs, 'yaxis');
title('Spectrogram of Filtered Pathological VAG Signal');
xlabel('Time (s)');
ylabel('Frequency (Hz)');
colorbar;
% Plot 7: Normal Signal Analysis Summary
subplot(4, 2, 7);
text(0.1, 0.5, {
'Normal VAG Signal Analysis Summary:', ...
['Number of Peaks Detected: ', num2str(length(peaks_normal))], ...
['Abnormal Detection: ', normal_status]}, ...
'FontSize', 10);
axis off;
% Plot 8: Pathological Signal Analysis Summary
subplot(4, 2, 8);
text(0.1, 0.5, {
'Pathological VAG Signal Analysis Summary:', ...
['Number of Peaks Detected: ', num2str(length(peaks_pathology))], ...
['Abnormal Detection: ', pathological_status]}, ...
'FontSize', 10);
axis off;
% Display Summary in Command Window
disp('---- VAG Signal Analysis Summary ----');
disp(['Normal Signal - Peaks Detected: ', num2str(length(peaks_normal)), ' -> Abnormal Detection: ', normal_status]);
disp(['Pathological Signal - Peaks Detected: ', num2str(length(peaks_pathology)), ' -> Abnormal Detection: ', pathological_status]);
Normal Signal - Peaks Detected: 72 -> Abnormal Detection: Yes Detection
Pathological Signal - Peaks Detected: 153 -> Abnormal Detection: Yes Detection
图片
本文转载自高斯的手稿