Question
Hello, I have a large sample of data (100000 samples) in txt file consisting of time and amplitude of the signal. I want to plot spectogram. The code is not at all able to extract the .txt file at all along the path. Kindly advice me as how to extract data from txt file when data is very large as it is in my case and hence to plot the spectogram. The code is as below: close all; freq_sam = 100000; % samples in tt1 data period_tt1 = 0.005; % time period freq_tt1 = 1/period_tt1; % frequency data = importdata('D:\Data_tokamak\data\obp.txt'); x_data = data(:,1); y_data = data(:,2); disp(x_data); disp(y_data); signal_tt1 = data; fft_tt1 = fft(signal_tt1); % fourier transform fft_tt1 = fftshift(fft_tt1); % performing fft shift f = freq_sam/2*linspace(-1,1,freq_sam); figure; plot(f, fft_tt1);
Expert Answer
Prashant Kumar
PhD Expert
Answered Aug 24, 2026
I prefer the pspectrum function for these analyses. See specifically Spectrogram and Reassigned Spectrogram of Chirp for an example of returning the data and plotting it as well.
data = readmatrix('D:\Data_tokamak\data\obp.txt');
x_data = data(:,1);
y_data = data(:,2);
Ts = mean(diff(x_data))
Fs = 1/Ts;
figure
pspectrum(y_data, Fs, 'spectrogram') % Plot 'pspectrum' 'spectrogram'
[sp,fp,tp] = pspectrum(y_data,fs,"spectrogram"); % Return Values, Then Plot
figure
waterfall(fp,tp,sp')
set(gca,XDir="reverse",View=[60 60])
ylabel("Time (s)")
xlabel("Frequency (Hz)")
Be certain that the ‘x_data’ are sampled uniformly. The easiest way to do that is to calculate the standard deviation (std) of ‘diff(x_data)’ and compare it to ‘Ts’. It should be vanishingly small, and preferably less than 1E-6 of the ‘Ts’ value.
It would help to have ‘obp.txt’ to work with.
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related spectogram Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →