how to store values for a further operation

1 vue (au cours des 30 derniers jours)
Anthony Koning
Anthony Koning le 26 Avr 2023
As the title implies, I would like to know how to store the values of parts of one function for use in a further part. For example, if I have a signal of 100 samples (x) that I want filtered for only 0-60 hz, I would filter the signal bandpass(x [0 60]). Let's call this inpute filt_x Now, if I wanted to perform a function like FFT on samples 30-40, how would I go about performing an FFT on only those specific values instead of having to FFT the whole signal and manually locate them?

Réponse acceptée

Star Strider
Star Strider le 26 Avr 2023
Perhaps something like this —
x = randn(2000, 1);
Fs = 250;
L = numel(x);
t = linspace(0, L-1, L).'/Fs;
figure
plot(t, x)
grid
xlabel('Time')
ylabel('Amplitude')
filt_x = lowpass(x, 60, Fs);
filt_x3040 = filt_x(30:40); % Select Segment Of Signal
Fn = Fs/2;
Lx = numel(filt_x3040);
NFFT = 2^nextpow2(Lx);
FTfilt_x3040 = fft(filt_x3040 .* hann(Lx), NFFT)/Lx;
Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
figure
plot(Fv, abs(FTfilt_x3040(Iv))*2)
grid
xlabel('Frequency')
ylabel('Magnitude')
title('Fourier Transform Of ‘filt\_x’ (30:40)')
The bandpass call as originally stated is actually a lowpass call. The bandpass passband must be greater than 0 and less than the Nyquist frequency.
.

Plus de réponses (0)

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by