MATLAB: How to extend the plot to draw negative values of the x-axis? Let’s say -4 to 0 dspgraph y = [8 2 5 3];Y = fft(y);figure(1);subplot(2,1,1)plot(abs(Y)),title('Magnitude'); Currently it only plots the x-axis from 1-4 Best Answer You would have to define a frequency (x-axis) vector going from -4 to +4 as well, and then use the fftshift function on your ‘Y’ (or fft) vector. Related SolutionsMATLAB: Using fft with rectangularPulse It is now: f=@(t) rectangularPulse(-1,1,t);time=-6:0.01:6;Fs = 1/0.01;Fn = Fs/2;Freq = linspace(-Fn, Fn, numel(time));pulse=f(time);fourier=fft(pulse);figure()subplot(3,1,1)plot(time,pulse) % Pulsesubplot(3,1,2)plot(Freq,fftshift(real(fourier))); % Magnitude of Fourierxlim([-10 10]) % (Optional)subplot(3,1,3)plot(Freq,fftshift(unwrap(angle(fourier)))); % Phase of Fourierxlim([-10 10]) % (Optional)Use fftshift to centre the amplitude and phase plots. I also calculated the frequency vector for the ‘fourier’ plots. MATLAB: How can i plot the magnitude and phase response the output signal The correct code for the Bode plot for your signal:t = linspace(0,10,4);Ts = mean(diff(t)); % Sampling IntervalFs = 1/Ts; % Sampling FrequencyFn = Fs/2; % Nyquist Frequencyx = [-3 8 5 2];y = fft(x);m = 2*abs(y)/length(x);f = linspace(0, 1, fix(length(y)/2)+1)*Fn;Iv = 1:length(f); % Index Vectorsubplot(2,1,1)plot(f,m(Iv))title('Magnitude')subplot(2,1,2)plot(f,angle(y(Iv)))title('Phase')xlabel('Frequency') Related QuestionHello,please could anyone tell me how to graph magnitude and phase spectra for given a .mat file (fs=8 kHz)Single sided spectrum of vector y obtained using fft
Best Answer