signal processing for feature extraction for use in matlab classification learner dimension error

2 次查看(过去 30 天)
The code I have here processes two signals and analyzes frequencies of interest based on fundamental frequency with a threshold of ± 200Hz. Within that threshold, it looks at the highest dBm value and returns it. I eventually want to put this data into a table for MATLAB’s classification learner but I am running into several issues before I can even run the code.
I am receiving an error message “Unable to perform assignment because the indices on the left side are not compatible with the size of the right side”. This error occurs when I am running with siglen of 1 so it won’t work with width(sigA).
I usually take the files and run it through another code that agrregrate all my signal into a sigular matrix so i can combine multiple signals into one file which would be converted to a table for the classification learner But nowI am even confused about how to put it in classification learner. does anyone have any suggestion on how to fix this issue of the indices and how to proceed with the features ? any and all suggestion is welcomed thank you
clc; clear;
%% This should be a combination data
SigA = load ("FM_PR_S6_305.mat");
SigB = load ("FM_PR_S7_305.mat");
SigA = SigA.FM_PR_S6_305;
SigB = SigB.FM_PR_S7_305;
%the .mat files contain data for signal files collected (ranging from 10-250)
% siglen = width(SigA);
siglen = 1;
p = 1;
frequencies = [ 2000, 4000, 6000, 8000, 10000, 12000, 14000, 16000];
freq_window = 200; % +/- 200 Hz
%% Loop through the signal
for lidx = 1:siglen
FeatureArray = [];
signal1 = SigA(:, lidx);
signal2 = SigB(:, lidx);
% Remove DC component
x1 = signal1 - mean(signal1);
x2 = signal2 - mean(signal2);
fs = 34000; % Sampling frequency
% FFT
y1 = fft(x1);
y2 = fft(x2);
% Get the power spectrum
p1 = abs(y1).^2/length(y1);
p2 = abs(y2).^2/length(y2);
% Only keep the first half of the points (single-sided spectrum)
halfLength = length(y1)/2+1;
p1 = p1(1:halfLength);
p2 = p2(1:halfLength);
f = fs*(0:(halfLength-1))/length(y1);
peak_info1 = [];
peak_info2 = [];
for freq = frequencies
idx_range1 = find(f >= (freq - freq_window) & f <= (freq + freq_window));
[~, peak_idx1] = max(p1(idx_range1));
peak_idx1 = idx_range1(peak_idx1);
peak_power1_dBm = 10*log10(p1(peak_idx1)/1e-3);
peak_info1 = [peak_info1; f(peak_idx1), peak_power1_dBm];
idx_range2 = find(f >= (freq - freq_window) & f <= (freq + freq_window));
[~, peak_idx2] = max(p2(idx_range2));
peak_idx2 = idx_range2(peak_idx2);
peak_power2_dBm = 10*log10(p2(peak_idx2)/1e-3);
peak_info2 = [peak_info2; f(peak_idx2), peak_power2_dBm];
%%
% Concatenate all the features
features = [peak_info1, peak_info2];
FeatureArray = [features];
end
%% to store the feature in a loop outside for saving and using later to merge with other data file and making it into a table for classicifcation learner
test(p,:) = FeatureArray;
p = p + 1;
end
  2 个评论
Ammar
Ammar 2023-6-16
I apologize for the delay i fixed the issue but here is the .mat file
clc; clear;
%% This should be a combination data
SigA = load ("FM_PR_S4_295.mat");
SigB = load ("FM_PR_S8_295.mat");
SigA = SigA.FM_PR_S4_295;
SigB = SigB.FM_PR_S8_295;
siglen = width(SigA);
% siglen = 272;
p = 1;
frequencies = [ 2000, 4000, 6000, 8000, 10000, 12000, 14000, 16000];
freq_window = 200; % +/- 200 Hz
%% Initialize the test matrix with enough columns for frequency and power
FM48FUND = zeros(siglen * length(frequencies) * 2, 2);
%% Loop through the signal
p = 1;
for lidx = 1:siglen
signal1 = SigA(:, lidx);
signal2 = SigB(:, lidx);
% Remove DC component
x1 = signal1 - mean(signal1);
x2 = signal2 - mean(signal2);
fs = 34000; % Sampling frequency
% FFT
y1 = fft(x1);
y2 = fft(x2);
% Get the power spectrum
p1 = abs(y1).^2/length(y1);
p2 = abs(y2).^2/length(y2);
% Only keep the first half of the points (single-sided spectrum)
halfLength = round(length(y1)/2+1);
p1 = p1(1:halfLength);
p2 = p2(1:halfLength);
f = fs*(0:(halfLength-1))/length(y1);
% First store info for signal 1
for freq = frequencies
idx_range1 = find(f >= (freq - freq_window) & f <= (freq + freq_window));
[~, peak_idx1] = max(p1(idx_range1));
peak_idx1 = idx_range1(peak_idx1);
peak_power1_dBm = 10*log10(p1(peak_idx1)/1e-3);
% Store frequency and power in the test matrix
FM48FUND(p,:) = [f(peak_idx1), peak_power1_dBm];
p = p + 1;
end
% Then store info for signal 2
for freq = frequencies
idx_range2 = find(f >= (freq - freq_window) & f <= (freq + freq_window));
[~, peak_idx2] = max(p2(idx_range2));
peak_idx2 = idx_range2(peak_idx2);
peak_power2_dBm = 10*log10(p2(peak_idx2)/1e-3);
% Store frequency and power in the test matrix
FM48FUND(p,:) = [f(peak_idx2), peak_power2_dBm];
p = p + 1;
end
end
sadly the ML part failed due to the sheer number of files that were present during training

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by