How do I Waveform,FFT that data?

I want to display the file as Waveform, FFT.(The attached file)
But I think my coding has a problem.
Can you look at it? I want to set the frequency in MHz
clear all; close all; clc;
[filename directory_name] = uigetfile('*.dat', 'Select a file');
fullname = fullfile(directory_name, filename);
data = load(fullname);
t = data(:,1)*1e-3; % Convert To‘seconds’ From ‘milliseconds’
v = data(:,2); % Voltage
L = length(t);
Ts = mean(diff(t)); % Sampling Interval (sec)
Fs = (1/Ts)*1e6; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
vc = v - mean(v); % Subtract Mean (‘0 Hz’) Component
FTv = fft(vc, L*4)/L; % Fourier Transform
Fv = linspace(0, 1, fix(length(FTv)/2)+1)*Fn; % Frequency Vector (Hz)
Iv = 1:length(Fv); % Index Vector
subplot(2,1,1);
plot(t,v);
title('Waveform');
xlabel('Time domain[ms]');
ylabel('Amplitude[mV]');
grid on;
subplot(2,1,2);
plot(Fv, abs(FTv(Iv))*2)
title('Spectrum');
xlabel('Frequency[MHz]');
ylabel('Magnitude[dB]');
grid on;

4 件のコメント

Walter Roberson
Walter Roberson 2018 年 5 月 7 日
Ameer Hamza
Ameer Hamza 2018 年 5 月 7 日
The first column of your data does not seem to represent time. It contains negative values. Also, the time samples are very close, what is the sampling frequency of the signal.
milksba
milksba 2018 年 5 月 7 日
I also checked the time frame is negative.
Fs = (1 / Ts) ; I did this.
No other sampling frequency has been set.
I followed the Internet.
Ameer Hamza
Ameer Hamza 2018 年 5 月 7 日
Yes, but how come the time is negative. Also, sampling frequency seems to be very large (in GHz). How can you display it in MHz.

回答 (0 件)

この質問は閉じられています。

タグ

質問済み:

2018 年 5 月 7 日

コメント済み:

2018 年 5 月 7 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by