How can i obtain different frequencies from a waveform using FFT?
Show older comments
I have a csv file which i used to plot data. I'm trying to use FFT in matlab to obtain the different frequencies this signal is made up of. My fft doesn't look correct. How can i fix this? First i try to use Savitzky Golay filter to smoothen the signal then take fft. below is my code and CSV has been attached.
clear all; close all; clc;
data = csvread('TEK00001.csv'); x=data(:,1); y=data(:,2);
Fs=100; polymonial_order=0; framelength=201; % plot(x,y) % hold on %%%%%%%%%%%%%%%%%% Savitzky Golay filter %%%%%%%%%%%%%%%%%%%%% new_data=sgolayfilt(data, polymonial_order,framelength); x_col1=new_data(:,1); y_col2=new_data(:,2);
new_data(:,2)=new_data(:,2)-min(new_data(:,2));
subplot(4,1,1) plot(x,y,'r') title('Original CSV waveform') grid on grid minor xlabel('Time [s]'); ylabel('Amplitude [mV] ');
subplot(4,1,2) plot(x_col1,y_col2,'b') title('Filtered waveform using Savitzky Golay Filter') grid on grid minor xlabel('Time [s]'); ylabel('Amplitude [mV]'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% nfft=length(data); nfft2=2^nextpow2(nfft); ff=fft(new_data,nfft2); %plot(abs(ff)); %plots the magnitude of signal xfft=Fs*(0:nfft2/2-1)/nfft2;
subplot(4,1,3) fff=ff(1:nfft2/2); plot(xfft,abs(fff))%plots the one symetrical side of fft signal title('FFT Magnitude') grid minor xlabel('Frequency [Hz]'); ylabel('Amplitude [mV]');
Accepted Answer
More Answers (0)
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!