The method of frequency domain analysis of signal based on Matlab

Matlab can be said to be a very useful and full-featured tool, which has a wide range of applications in communications, self-control, and finance.

This article discusses the method of using Matlab to analyze the signal in the frequency domain.

When it comes to frequency domain, Fourier transform is unavoidable. Fourier transform provides a way to transform a signal from time domain to frequency domain. The frequency domain analysis of the signal is necessary because many signals that are not obvious in the time domain can be well displayed in the frequency domain, which can be analyzed and processed more easily.

FFT

The function of the Fourier transform provided by Matlab is FFT, and the Chinese name is called Fast Fourier Transform. The proposal of fast Fourier transform is great, which greatly improves the processor's ability to process digital signals, and also makes our lives a big step towards digitization.

Next, let's talk about how to use this function.

Fft is very simple to use, but generally signals have x and y vectors, while fft only processes the y vector, so if you want the frequency domain analysis to be meaningful, you need to process the x vector by yourself

A simple example

Let’s start with a simple sinusoidal signal, which is defined as:

We now draw this sine curve in Matlab through the following code

fo=4;%frequencyofthesinewave

Fs=100;%samplingrate

Ts=1/Fs;%samplingTImeinterval

t=0:Ts:1-Ts;%samplingperiod

n=length(t);%numberofsamples

y=2*sin(2*pi*fo*t);%thesinecurve

%plotthecosinecurveintheTImedomain

sinePlot=figure;

plot(t, y)

xlabel('TIme(seconds)')

ylabel('y(t)')

TItle ('SampleSineWave')

grid

This is what we get:

The method of frequency domain analysis of signal based on Matlab

When we fft this curve, we hope to get the following spectrum in the frequency domain (based on the Fourier transform theory, we hope to see a peak with an amplitude of 1 at -4Hz and the other at +4Hz)

The method of frequency domain analysis of signal based on Matlab

Use the FFT command

We know what the target is, so now use Matlab's built-in FFT function to regenerate the spectrum

%plotthefrequencyspectrumusingtheMATLABfftcommand

matlabFFT=figure;%createanewfigure

YfreqDomain=fft(y);%takethefftofoursinwave, y(t)

stem(abs(YfreqDomain));%useabscommandtogetthemagnitude

%similary, we would use anglecommandtogetthephaseplot!

%we'lldiscussphaseinanotherpostthough!

xlabel('SampleNumber')

ylabel('Amplitude')

title('UsingtheMatlabfftcommand')

grid

axis([0, 100, 0, 120])

The effect is as follows:

The method of frequency domain analysis of signal based on Matlab

But note that this is not what we really want, some information is missing

The x-axis should provide us with frequency information, but can you read the frequency?

Both amplitudes are 100

Without letting the center of the spectrum be

Define a function for FFT to obtain bilateral spectrum

The following code can simplify the process of obtaining bilateral spectrum, copy and save it to your .m file

function [X, freq]=centeredFFT(x, Fs)

%thisisacustomfunctionthathelpsinplottingthetwo-sidedspectrum

%xisthesignalthatistobetransformed

%Fsisthesamplingrate

N=length(x);

%thispartofthecodegeneratesthatfrequencyaxis

ifmod(N, 2)==0

k=-N/2:N/2-1;%Neven

else

k=-(N-1)/2: (N-1)/2;%Nodd

end

T=N/Fs;

freq=k/T;%thefrequencyaxis

%takesthefftofthesignal, andadjuststheamplitudeaccordingly

X=fft(x)/N;%normalizethedata

X=fftshift(X);%shiftsthefftdatasothatitiscentered

This function outputs the correct frequency domain range and transformed signal. It needs to input the signal to be transformed and the sampling rate.

Next, use the sine signal in the previous article to make a simple example. Note that your example .m file and the centeredFFT.m file should be in the same directory as the centeredFFT.m file.

[YfreqDomain, frequencyRange]=centeredFFT(y, Fs);

centeredFFT=figure;

%remembertotaketheabsofYfreqDomaintogetthemagnitude!

stem(frequencyRange, abs(YfreqDomain));

xlabel('Freq(Hz)')

ylabel('Amplitude')

title('UsingthecenteredFFTfunction')

grid

axis ([-6, 6, 0, 1.5])

The effect is as follows:

The method of frequency domain analysis of signal based on Matlab

This picture satisfies our needs. We got the peaks at +4 and -4, and the amplitude is 1.

Define a function for FFT to get the right spectrum

As can be seen from the above figure, the frequency spectrum obtained by FFT is symmetrical. Therefore, we only need one side to obtain all the information of the signal, and we generally keep the positive frequency side.

The following function has made some modifications to the above custom function, so that it can help us to draw only the positive frequency side of the signal

function [X, freq]=positiveFFT(x, Fs)

N=length(x);%getthenumberofpoints

k=0:N-1;%createavectorfrom0toN-1

T=N/Fs;%getthefrequencyinterval

freq=k/T;%createthefrequencyrange

X=fft(x)/N;%normalizethedata

%onlywantthefirsthalfoftheFFT, sinceitisredundant

cutOff=ceil(N/2);

%takeonlythefirsthalfofthespectrum

X=X(1:cutOff);

freq=freq(1:cutOff);

As before, use a sine signal as an example, the following is the sample code

[YfreqDomain, frequencyRange]=positiveFFT(y, Fs);

positiveFFT=figure;

stem(frequencyRange, abs(YfreqDomain));

set(positiveFFT,'Position', [500, 500, 500, 300])

xlabel('Freq(Hz)')

ylabel('Amplitude')

title('UsingthepositiveFFTfunction')

grid

axis([0, 20, 0, 1.5])

The effect is as follows:

The method of frequency domain analysis of signal based on Matlab

ZGAR TWISTER Vape

ZGAR TWISTER Disposable


ZGAR electronic cigarette uses high-tech R&D, food grade disposable pod device and high-quality raw material. All package designs are Original IP. Our designer team is from Hong Kong. We have very high requirements for product quality, flavors taste and packaging design. The E-liquid is imported, materials are food grade, and assembly plant is medical-grade dust-free workshops.


Our products include disposable e-cigarettes, rechargeable e-cigarettes, rechargreable disposable vape pen, and various of flavors of cigarette cartridges. From 600puffs to 5000puffs, ZGAR bar Disposable offer high-tech R&D, E-cigarette improves battery capacity, We offer various of flavors and support customization. And printing designs can be customized. We have our own professional team and competitive quotations for any OEM or ODM works.


We supply OEM rechargeable disposable vape pen,OEM disposable electronic cigarette,ODM disposable vape pen,ODM disposable electronic cigarette,OEM/ODM vape pen e-cigarette,OEM/ODM atomizer device.



ZGAR TWISTER Vape,ZGAR TWISTER Vape disposable electronic cigarette,ZGAR TWISTER Vape pen atomizer ,ZGAR TWISTER Vape E-cig,TWISTER Vape disposable electronic cigarette

ZGAR INTERNATIONAL(HK)CO., LIMITED , https://www.zgarette.com