Do a zoom in a FFT trasform
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Domenico Domenico
am 16 Apr. 2016
Kommentiert: Domenico Domenico
am 18 Apr. 2016
Hi, i do this exercise, but i dont know how to do a zoom in a fft function. I want that my plot go from fc-span/2 to fc+span/2, where span is an input value. i want to see only a part of my fft trasform, and not the all spectrum.
Esercize: Design a MATLAB function that accepts the following input parameters: the frequency f0 of the input sinewave the amplitude A of the input sinewave center frequency span window vertical scale. As far as f0, A, center frequency and span go, they have to be numerical input variables. Instead the remaining input variables values have to be chosen among a pre-dened set of values that can be specied in the help of the function. The function output is the plot of the measured spectrum. Remember to set the x-axis and y-axis labels.
This is my code:
function FFT_Analyzer(f0, A,center_freq, span, window)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
fc=center_freq;
s=span;
w=window;
%vs=vertical_scale;
fs=f0*5; %sampling rate choisen in order to respect Nyquist Theorem
ts=1/fs; %sapling time
m=256; %window length
Tobs=m*ts; %observation time
t=0:ts:Tobs-ts;
x=A*sin(2*pi*f0*t);
n=pow2(nextpow2(m));
% function for set the imposed center frequency
xs=x.*exp(j*2*pi*fc*t);
% function to trasform an arbitrary span into a cardinal span
if(s==0)
f=(0:n/2)*(fs/n);
else
a=pow2(nextpow2(s));
b=a/4;
if (a-s>=b)
s1=pow2(floor(log2(s)));
else
s1=a;
end
N=fs/(2*s1); %decimation factor
df=fs/N; %new resolution
f=linspace(fc-s1/2,fc+s1/2,df/2+1);
end
% if cicle to choise the window to use in the windowing process
if(strcmp(w,'hamming'))
w1=hamming(m);
elseif(strcmp(w,'hanning'))
w1=hanning(m);
elseif(strcmp(w,'flattop'))
w1=flattopwin(m);
elseif(strcmp(w,'rectangular'))
w1=rectwin(m);
else
display('use hamming, hanning, flattop, rectangular for the window')
end
x1=x.*w1';
y=fft(x1,n);
y_mag=abs(y)/sum(w1);
plot(f,y_mag(1:length(f)));
xlabel('Frequency[Hz]');
end
Remember i dont know how to implemet the zoom function in my code, to have a video not the all spectrum, but only a range that i decide whit the value on span in the function.
0 Kommentare
Akzeptierte Antwort
Ced
am 16 Apr. 2016
You can specify the portion of the plot displayed using xlim, ylim, or axis (for both x and y). This will not change what you are actually plotting, only what you see.
So e.g.
xlim([ 0 0.25*fs])
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Fourier Analysis and Filtering finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!