Azizur_rahman asked . 2021-03-12

2nd order butterworth filter and PCA

 I am performing a FFT on my accelerometer data, but I am having issues with the 2nd-order Butterworth filter and pca interpretation. Please find a snippet of my code below.
 
RE the 2nd-order Butterworth filter, I am trying to first, downsample to 100 Hz (haven't managed to do this yet), and then bandpass filter using a second-order Butterworth filter between 3-15 Hz. However, I keep getting the error: "The cutoff frequencies must be within the interval of (0,1). Would anyone be able to assist me with this - specifically, highlight where in the code I am going wrong?
 
Regarding the pca, the anwser below (bolded) is the anwser from the pca. The columns represent 'x, z, y' - does this suggest that the Y is the most dominant (movement-centred) axis of tremor acceleration? From plotting, this seems correct but I'd like some confirmation (plot not included in the code provided below).
 
PCA ans = 0.9780 -0.1221 0.1694
 
-0.0357 0.7013 0.7120
 
0.2057 0.7023 -0.6815
 
 
t = data(:,1);                                                                                              % column corresponding to time (block of 60s)
Accel = data(:,2:end);                                                                               % three columns corresponding to x, y, z (accelerometer data)
srate = 5000;                                                                                            % Hz (need to figure out how to downsample to 100Hz)
Fs = 1/srate;                                                                                             % Sampling Rate (in Hz) 
Fn =Fs/2;                                                                                                  % Nyquist Frequency (in Hz)
coeff = pca(Accel);                                                                                   % Need to obtain the most dominant (movement-centred) axis of tremor acceleration; use                  first component for all subsequent analyses
%2nd order Butterworth filter between 3-15 Hz
Wp = [3  15]/Fn;                                         % Norrmalised Passband Frequencies
Ws = [1.5   15.99]/Fn;                                   % Normalised Stopband Frequencies
Rp =  1;                                                 % Passband Ripple (dB)
Rs = 25;                                                 % Stopband Ripple (dB)
[n,Wn] = buttord(Wp, Ws, Rp, Rs);                        % Optimal Filter Order
[b,a] = butter(n, Wn);                                   % Calculate Filter Coefficients
[sos,g] = tf2sos(b,a);                                   % Convert To Second-Order Sections For Stability
figure(1)
freqz(sos, 4096, Fs)                                     % Filter Bode Plot

 

matlab , signal , signal processing

Expert Answer

Kshitij Singh answered . 2024-05-17 20:42:14

With respect to downsampling, use the resample function. I wouldn’t downsample the signal unless you absolutely must for some reason. Most of the time, I use resample to create a unifformly-sampled  signal from a non-uniformly-sampled signal, since all signal processing requires uniform sampling. If you do decide to downsample, be sure to change ‘Fs’ to reflect that, if you’re doing the filtering after the downsampling.
 
I don’t understand this assignmment:
 
srate = 5000;
If ‘srate’ is your sampling rate, it’s actually ‘Fs’, the sampling frequency, so assign it to ‘Fs’ instead. That’s also the indirect cause of the error you’re getting.
With that correction, the rest of your code should work. (It looks like I wrote it!)
 
I would also make two change these assignments:
 
[b,a] = butter(n, Wn);                                   % Calculate Filter Coefficients
[sos,g] = tf2sos(b,a);                                   % Convert To Second-Order Sections For Stability
to:
 
 
[z.p,k]] = butter(n, Wn);                                % Calculate Filter Coefficients
[sos,g] = zp2sos(b,a);                                   % Convert To Second-Order Sections For Stability
That will design a better filter that the code I originally wrote.
 
And of course, use filtfilt to do the actual filtering.


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.