I enabled fft function in oscillioscope and it saved the data as FFT amplitude (dBV) and frequency domain how ever I want my time domain and ampltude signals original data.
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
%%
folder = 'C:\Users\haneu\OneDrive\바탕 화면\New folder (2)';
filename = '550mvp.csv';
data = readtable(fullfile(folder,filename));
frequency = table2array(data(3:end,1));
amplitude = table2array(data(3:end,2));
figure,plot(frequency/1e6,amplitude)
xlim([0,15])
xlabel('Frequency [MHz]'),
grid on,
ylabel('Amplitude[dBV]')
Accepted Answer
Star Strider
on 14 Jul 2024
Edited: Star Strider
on 14 Jul 2024
You cannot reliably invert a Fourier transforom unless you also have the phase information. Lacking the phase information, you can still invert it, however the result will not be reliable and may not reflect the actual time-domain signal. The best approach is to record the time-domain signal and calculate the Fourier transform afterwards.
One approach —
RL = readlines('550mvp.csv');
H1 = split(RL(1,:),',');
H2 = split(RL(2,:),',');
T1 = readtable('550mvp.csv', 'HeaderLines',2);
T1.Properties.VariableNames = H1.'
T1 = 4002x2 table
x-axis 1
___________ __________
-2.46e-05 0.025633
-2.4575e-05 0.019603
-2.455e-05 0.0099925
-2.4525e-05 0.0015126
-2.45e-05 -0.0065276
-2.4475e-05 -0.014568
-2.445e-05 -0.023048
-2.4425e-05 -0.030648
-2.44e-05 -0.036678
-2.4375e-05 -0.042709
-2.435e-05 -0.044719
-2.4325e-05 -0.048739
-2.43e-05 -0.052759
-2.4275e-05 -0.052759
-2.425e-05 -0.056339
-2.4225e-05 -0.052759
NrMissing = nnz(ismissing(T1))
NrMissing = 4
T1 = fillmissing(T1, 'linear');
figure
plot(T1{:,1}, T1{:,2})
grid
xlabel(H2(1,:))
ylabel(H2(2,:))

L = height(T1)
L = 4002
Fn = max(T1{:,1}); % Nyquist Frequency
Fs = Fn*2; % Sampling Frequency
Ts = 1/Fs; % Sampling Interval
Lt = 2*L; % Assumed Length Of Original Time-Domain Signal
t = linspace(0, Lt-1, Lt)/Fs; % Time Vector
v = ifft([T1{:,2}; flip(T1{:,2})],'symmetric');
v = 8004x1
-48.7696
31.5389
-0.9678
-10.0265
0.5044
6.0149
-0.5402
-4.1703
0.5625
2.9814
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
figure
plot(t, v)
grid
xlabel('Time')
ylabel('Volt')
xlim([min(t) max(t)])

figure
plot(t, v)
grid
xlabel('Time')
ylabel('Volt')
xlim([min(t) 1E-6])

This initially re-creates the full ‘original’ two-sided Fourier ttransform by appending a flipped version of the original one-sided Fourier transform to it and then doing the inversion. The highest frequency is assumed to be the Nyquist frequency here, and the sampling frequency and sampling intervals are calculatted from it.
.
EDIT — Corrected typographical errors.
EDIT — (14 Jul 2024 at 13:24)
Forgot the symmetry flag in the ifft call. Added now.
.
10 Comments
Always a pleasure to read a good answer.
Honey
on 14 Jul 2024
I see the amplitude I gave was in mili Volt peak to peak.Is there a posibility to plot a spectrogram with current data I have.I see time domain signals are not exactly the same you are right the pase information is lacking.
Honey
on 14 Jul 2024
I appreciate your help. :)
@Honey — As always, my pleasure!
To plot the spectrogram, use the reconstructed time-dopmain signal, or preferably tthe original time-domain signal if you have it. I generally prefer the pspectrum function witth the 'spectrogram' option because it calculates the power spectrum spectrogram (units are dB), not the power density spectrogram (units are dB/Hz).
Honey
on 14 Jul 2024
hey thanks for your help I got the time domain data save its saved seperately in Csv file for fft and time domain.sorry for the trouble:p
@Honey — No trouble at all!
Here’s my one-sided Fourier transform function, in the event you want to use it —
function [FTs1,Fv] = FFT1(s,t)
% Arguments:
% s: Signal Vector
% t: Associated Time Vector
t = t(:);
L = numel(t);
if size(s,2) == L
s = s.';
end
Fs = 1/mean(diff(t));
Fn = Fs/2;
NFFT = 2^nextpow2(L);
FTs = fft((s - mean(s)) .* hann(L).*ones(1,size(s,2)), NFFT)/sum(hann(L));
Fv = Fs*(0:(NFFT/2))/NFFT;
% Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
FTs1 = FTs(Iv,:);
end
I wrote it because I was simply tired of typing the same code every time I wanted to use the fft function.
.
Honey
on 15 Jul 2024
once again Thanks alot.
As always, my pleasure!
Honey
on 16 Jul 2024
@Star Strider Hi I have a question related to pspectrum.I have csv file related to different voltage data.I used p spectrum function to plot the spectrogram and visualize the data however despite setting frequency limits the 10MHz frequency content wouldnot be displayed and also time axis I believe is not right.I believe there is no consistency in both the data.could you tell why its happening.
folder = 'C:\Users\Min\Desktop\New folder (2)\New folder (2)';
filename = '240mvp1.csv';
data = readtable(fullfile(folder, filename));
t = table2array(data(3:end, 1));
x = table2array(data(3:end, 2));
time_resolution = t(end)-t(1);
fs = 1/mean(diff(t));
pspectrum(x,fs,'spectrogram', ...
'FrequencyLimits',[1e5 7e6],'TimeResolution',time_resolution,'OverlapPercent',90)
% Customize the plot
xlabel('Time (s)');
ylabel('Frequency (MHz)');
colormap("jet")
title('Spectrogram');
colorbar;
Since your signals have a time vector, it is best to use it as an appropriate argument. (The only problem is tthat not all the time values are unique, so I use the resample function to create vectors that will work with pspectrum.) Note that tthis makes the time values the same as the argument times. The time values that pspectrum uses are still a bit strange (in my opinion, I have not explored that in detail) however they represent the time ranges in the argument vectors. I also plotted a sample of the original vectors to get an idea of what they looked like. This is close to the way I use pspectrum (generally using the default arguments, though).
Try this —
files = dir('*.csv');
for k = 1:numel(files)
filename = files(k).name
RL = readlines(filename);
H1 = split(RL(1,:),',');
H2 = split(RL(2,:),',');
data = readtable(filename, 'HeaderLines',2);
t = data{:,1};
x = data{:,2};
% time_resolution = t(end)-t(1);
% time_resolution = mean(diff(t));
zxi = find(diff(sign(x)));
fs = 1/mean(diff(t))
[xr, tr] = resample(x, t, fs);
figure
plot(tr, xr)
grid
xlabel('t')
ylabel('Volt')
title(filename)
xlim([-1 1]*2E-6)
figure
% pspectrum(x,fs,'spectrogram', ...
% 'FrequencyLimits',[1e5 7e6],'TimeResolution',time_resolution,'OverlapPercent',90)
pspectrum(xr, tr, 'spectrogram', 'FrequencyLimits',[1e5 7e6], 'OverlapPercent',90)
% Customize the plot
xlabel('Time (s)');
ylabel('Frequency (MHz)');
colormap("jet")
title('Spectrogram');
colorbar;
end
filename = '270mvp3.csv'
fs = 1.0015e+07


filename = '550mvp.csv'
fs = 39980000


.
More Answers (0)
Categories
Find more on Spectral Measurements in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)