plot the magnitude of xpfq in the frequency range fs{2 ¤ f ¤ fs{2, where fs is the sampling frequency. in matlab

To plot the magnitude of xpfq in the frequency range from 2/fs to fs/2, first we need to take the FFT of xpfq. We can use the fft function in MATLAB to do this.

main.m
Fs = sampling_frequency; % define the sampling frequency
X_fft = fft(xpfq); % take the FFT of xpfq
99 chars
3 lines

Next, we need to compute the frequency vector corresponding to the FFT. We can use the linspace function to create a vector of frequency values spanning from -fs/2 to fs/2, with a length equal to the length of X_fft.

main.m
N = length(X_fft); % length of FFT
f = linspace(-Fs/2, Fs/2, N); % frequency vector
84 chars
3 lines

To get the frequency range from 2/fs to fs/2, we can create a logical index vector for the frequency vector and use it to select the relevant portion of X_fft.

main.m
idx = (f >= 2/Fs & f <= Fs/2); % logical index for relevant frequency range
X_mag = abs(X_fft(idx)); % magnitude of relevant portion of FFT 
f_range = f(idx); % frequency values for relevant portion of FFT
206 chars
4 lines

Finally, we can plot the magnitude of X_fft in the relevant frequency range using the plot function.

main.m
plot(f_range, X_mag)
xlabel('Frequency (Hz)')
ylabel('Magnitude')
title('Magnitude of xpfq in frequency range 2/fs - fs/2')
124 chars
5 lines

gistlibby LogSnag