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);
Prashant Kumar answered .
2025-11-20
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)")