MATLAB: generating Eye Diagram of a time-domain signal - matlab

I have a csv file of time signal. The data has been extracted from Cadence Virtusuo. I can simulate in Virtusuo and get the Eye Diagram of the signal over the 30ns period and using 500ps time step. Now I wanted to generate the same plot in MATLAB. But my MATLAB code doesn't generate same eye diagram as I see in the Virtusuo SImulator.
Can anyone help me to get the plot that I want to generate in MATLAB. Here is the Data in csv and the desired eye diagram image from Cadence Virtusuo has been given. My MATLAB code is given also.
Desired Eye Diagram:
MATLAB code:
% open data file
fid = fopen('Data.csv');
readData = textscan(fid,'%f %f','Headerlines',1,'Delimiter',',');
% Extract data from readData
xData = readData{1,1}(:,1);
yData = readData{1,2}(:,1);
eyediagram(yData,300,10e-10);
plottools
MATLAB Generated Plot:

Related

How to extract a particular independent component from various ICA components in EEGLAB gui in MATLAB?

I'm currently doing a project on BCI motor imagery dataset. My interest is to extract that necessary component by ICA method. I'm currently using EEGLAB for that purpose. Can you please help me as how to extract the independent component variable from the GUI to the workspace of MATLAB?
After running ICA on datasets in eeglab, ICA weights are saved in icaweights matrix in the EEG struct (you can see the EEG struct in workspace when your data is loaded in eeglab), in order to convert icaweights to the signals you see in plot>Component Activations, assuming this is what you want to extract, do the following:
First you'll need to load your data, file>load existing dataset.
Choose the components you want to extract and save them as a vector. As an example here, I'll choose components 5 and 9:
comp_idx = [5 9]; %id of channels we extract
Transform the channel data(here denoted Y) to ICA activations(Y_ICA) as below:
Y = EEG.data; % set channel data to matrix Y
ica_weights = EEG.icaweights; % copy icaweights matrix
Y_ICA = ica_weights*Y; % Component Activations
Y_ICA now contains all the component activations, use Y_ICA(comp_idx,:) to extract only the components you need, you can do operations on this new matrix such as summing up both components and plot:
%% Mix components and plot
figure;
S = sum( Y_ICA(comp_idx,:) );
plot(EEG.times, S, 'r') % EEG.times contains the time data
title('Mix of all Channels')
Or plot each component separately:
%% Plot each component
figure;
plot( EEG.times, Y_ICA(comp_idx(1),:))
hold on
plot( EEG.times, Y_ICA(comp_idx(2),:))
A Note: if your data is made up of epochs, then the EEG.data matrix will be a three dimensional matrix, the 3rd dimension being the epoch sets, so you will have to do the above procedure for each epoch, that is, Y = EEG.data(:,:,epoch_i) and iterate for epoch_i = 1:size(EEG.data,3)
I'm not sure if ReZzT's answer is completely right.
Looking at the eeg_getdatact.m file
edit eeg_getdatact
it can be seen that the component activations are calculated with an additional matrix multiplication (with icasphere). Look at lines 179-180:
data = eeg_getdatact( EEG );
data = (EEG.icaweights(opt.component,:)*EEG.icasphere)*data(EEG.icachansind,:);
which, simplified, the last line can be written as:
data = (EEG.icaweights*EEG.icasphere)*eegdata;

Taking IFFT2 of data set and what is means

I am dealing with a data set collected from a bistatic radar system which has electric field amplitude vs frequency points. I am trying to take the inverse fourier transform of the data set, converting from the frequency domain into the time domain. I have read in the data in the code below, created two different arrays, one for freq and one for amplitude. I correctly plot the data, but when I take the IFFT of the data I do not get what i expect.
Can someone tell me how to properly take the 2 dimensional fast fourier transform of the data set in matlab, and what exactly the IFFT in this case scenario is showing?
waves = csvread('10cm.txt');
A = waves(:,1);
B = abs(waves(:,2));
Matrix = [A B];
waves_transform = abs(ifft2(Matrix));
figure, plot(A,B), title('Frequency Domain'), xlabel('Frequency'),ylabel('amplitude');
figure, plot(waves_transform),title('Time Domain'), xlabel('Frequency'),ylabel('amplitude');
%axis([0 5 0 17*10^9]);
10cm.txt DATA FILE HERE: http://pastebin.com/0t0TwVvC
code output

Plotting my .wav file in the time domain instead of freq. domain in MATLAB?

I'm writing a Matlab program to perform a convoluted sum of two signals. I first started out creating a simple sinusoidal signal and a carrier signal. I convoluted the two and created the convoluted signal. You can see that my (x) axis is specified in the time domain. My code and a screen shot of my plot is shown below for clarity.
MY CODE:
note: This program doesn't use the .wav file and instead uses a simple sinusoidal signal.
mySignalFreq = 1E3;
%T = 1/f;
T = 1/mySignalFreq;
tmin = 0;
tmax = 5*T;%i want to graph 5 time periods
dt = T/60;%used 60 to specify spaceing of time domain
t = tmin:dt:tmax;
myCarrierFreq = 560E3;
Bandwidth = 10E3;
omega_mySignal = 2*pi*mySignalFreq;%determine angular frequency
omega_myCarrier = 2*pi*myCarrierFreq;%determine angular frequency
modIndex = 0.8;%modulation index
myCarrierAmp = 4.0;%amplitude of carrier signal
ys = sin(omega_mySignal*t);
yc = sin(omega_myCarrier*t);
convSum = myCarrierAmp*(1+modIndex.*ys).*yc;%Convolution Sum
%create txt file with Write permissions
convolutionData.txt = fopen('convolutionData.txt','w');
%7.5 specifies 7digits and 5digits to the right of decimal
%have to use \r\n for readability
%array of values need to be in [x;y1;y2;y3] format
%comma in the function denotes the seperator
fprintf(convolutionData.txt,'%7.5f,%7.5f,%7.5f,%7.5f\r\n',[t;ys;yc;convSum]);
%close out file
fclose(convolutionData.txt);
%creating a basic plot of all three signals
plot(t,ys,'r',t,yc,'g',t,convSum,'b');
title('Convoluted Signal');
xlabel('Time Periods');
ylabel('Amplitude (Volts)');
grid on;
This is the picture of the plot above. You can see that i'm using the variable 't' as my x axis data.
I have finally figured out some code that plots my .wav file i created with a recorder. However, it's plots it in the frequency domain. As you can see in the code i'm reading the data in the .wav file into what I'm understanding is an array. Not quite understanding this part so if someone could explain more on that as a side note that would be great.
My main question is how do I incorporate the data from my .wav file into my original code above so it can be plotted in the time domain like my plot above? Just can't figure that part out because the code below is just doing it in the frequency domain.
Here is the code and plot of the .wav file
[wave,fs]=audioread('myvoice1.wav');
t=0:1/fs:(length(wave)-1)/fs;
subplot(2,1,1);
plot(t,wave);
n=length(wave)-1;
f=0:fs/n:fs;
wavefft=abs(fft(wave));
subplot(2,1,2);
plot(f,wavefft);
The upper subfigure in your last plot already is the right signal, so the t and wave are the right variables.
Only the second subfigure in your last plot is the frequency domain (represented in the wavefft variable).
Just use the wave variable and you should have what you want.

power spectral density coding in Matlab on my EEG signal?

Okay, I need to apply PSD on my EEG signal.. My current program code is below where y_theta is my data name.
The problem is, I was asked by my lecturer to create another plot using PSD but without changing the amplitude into dB/Hz (which is the y axis)..How can I do that?
length(y_theta)
nfft = 2^nextpow2(length(y_theta));
Fs=128;
Pxx = abs(fft(y_theta,nfft)).^2/length(y_theta)/Fs;
subplot(2,2,2),
plot(Pxx,'DisplayName','Pxx','YDataSource','Pxx');
Hpsd = dspdata.psd(Pxx(1:length(Pxx)/2),'Fs',Fs);
plot(Hpsd);

MATLAB - Plot time-frequency graph of .wav file

I'm working on a project that involves looking at the changes in pitch/frequency over time with a wave file (I'm new to MATLAB, but not to programming). I'm able to see the time-amplitude graph and frequency-amplitude (after an FFT) graph, but how would I be able to isolate the frequency and show it at each point in time?
Code:
filename = '/Users/Username/Sample_1.wav'
[y, fs] = wavread(filename);
y = y(:,1);
dt = 1/fs;
t = 0:dt:(length(y)*dt)-dt;
plot(t,y); xlabel('Seconds'); ylabel('Amplitude');
transformed = fft(y);
mag = abs(transformed);
plot(mag);
If you have the Signal Processing Toolbox, then you may find the spectrogram function useful.
If you don't, then you can achieve the same effect manually by calculating FFTs of consecutive (possibly overlapped) windowed segments of your time-domain data, and then plotting the amplitudes.
This is essentially the short-time Fourier transform (STFT).
If you have the Signal Processing Toolbox, spectrogram is the way to go (as Oli Charlesworth mentioned).
If you don't have it, the MATLAB Central File exchange is always a good place to look for something that general.
http://www.mathworks.com/matlabcentral/fileexchange/1553-spectrogram-short-time-ft-log-magnitude
This seems to be a sensible and well working implementation of the spectrogram functionality.