Advertisement
makispaiktis

Course 4 - Filters code

Sep 3rd, 2023
1,092
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.01 KB | None | 0 0
  1. clear all
  2. close all
  3. clc
  4.  
  5.  
  6. % 1. Compute spectrogram
  7. timeLimits = [0 902.12]; % seconds
  8. frequencyLimits = [0 25]; % Hz
  9. overlapPercent = 50;
  10.  
  11. % 2. Index into signal time region of interest
  12. wanc_bandpass_ROI = wanc_bandpass(:);
  13. sampleRate = 50; % Hz
  14. startTime = 0; % seconds
  15. timeValues = startTime + (0:length(wanc_bandpass_ROI)-1).'/sampleRate;
  16. minIdx = timeValues >= timeLimits(1);
  17. maxIdx = timeValues <= timeLimits(2);
  18. wanc_bandpass_ROI = wanc_bandpass_ROI(minIdx&maxIdx);
  19. timeValues = timeValues(minIdx&maxIdx);
  20.  
  21. % 3. Compute spectral estimate
  22. [P,F,T] = pspectrum(wanc_bandpass_ROI, timeValues, 'spectrogram', ...
  23.     'FrequencyLimits',frequencyLimits, 'OverlapPercent',overlapPercent);
  24.  
  25.  
  26. % 4. Auxiliary Function
  27. function y = preprocess(x,tx)
  28.  
  29.     %    This function expects an input vector x and a vector of time values
  30.     %    tx. tx is a numeric vector in units of seconds.
  31.     Fs = 1/mean(diff(tx)); % Average sample rate
  32.     y = bandpass(x,[2 10],Fs,'Steepness',0.85,'StopbandAttenuation',60);
  33.  
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement