Data won't load
1 次查看(过去 30 天)
显示 更早的评论
d.data=importdata('a2.txt'); % import data options
fs=100; % Sampling frequency
fc=40; % carrier frequency (corner frequency)
fc_n = fc .* 2 /fs; % normalized frequency
B = fir1(10000,fc_n); % filter basics
z1=filter(B,1,d.data(:,2)); % I channel signal
z2=filter(B,1,d.data(:,4)); % Q channel signal
I=z1; % I data filtered
Q=z2; % Q data filtered
hiFreq =20;
S = size (I); % Check the size of data
fs = 100; % Sampling Frequency
%fs=1000; % Samopling frequency
f = 2440e6; % Carrier Frequency
%f=24e9; % carrier frequency
lambda = 3e8/f; % Calculate wavelength of carrier signal
% Convert # of samples to time
Array = 1:1:S(1,1);
Array = Array';
Time = Array/fs;
% Time = Time(100:end,1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DC_Removing
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I_no_dc = I - mean (I);
Q_no_dc = Q - mean (Q);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Arctangent demodulation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Xt = atan2(Q_no_dc, I_no_dc);
Xt = unwrap(Xt);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Displacement Calculation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
D = (lambda .* Xt)/(4*pi);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FFT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Nsamps = length(Xt); % Window length
y_fft = abs(fft(Xt)); %Retain Magnitude
y_fft = y_fft(1:Nsamps/2); %Discard Half of Points
% y_fft_dc = abs(fft(Xt_dc)); %Retain Magnitude
% y_fft_dc = y_fft_dc(1:Nsamps/2); %Discard Half of Points
f = fs*(0:Nsamps/2-1)/Nsamps; %Prepare freq data for plot
I_fft = abs(fft(I)); %Retain Magnitude
I_fft = I_fft(1:Nsamps/2); %Discard Half of Points
Q_fft = abs(fft(Q)); %Retain Magnitude
Q_fft = Q_fft(1:Nsamps/2); %Discard Half of Points
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Power Spectrum Density
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
P_I = 1/(Nsamps*fs)*abs(I_fft(1:Nsamps/2)).^2;
P_Q = 1/(Nsamps*fs)*abs(Q_fft(1:Nsamps/2)).^2;
[y_max index] = max(P_I(2:end));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot Graphs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure (1);
subplot(2,1,1) % new subplot option
plot (Time, I,'LineWidth',2);
hold on;
title ('Raw data', 'FontSIze', 20);
subplot(2,1,2)
plot (Time, Q, 'r','LineWidth',2);
legend ('I','Q');
xlabel ('Time [s]', 'FontSize', 20);
ylabel ('Amplitude [V]', 'FontSize', 20);
set(gca,'FontSize',20);
figure(2);
subplot(3,1,1);
plot (I, Q);
title ('IQ Plot', 'FontSIze', 20)
xlabel ('I [V]', 'FontSize', 20);
ylabel ('Q [V]', 'FontSize', 20);
axis equal;
set(gca,'FontSize',20);
figure (3);
plot (Time, D,'LineWidth',2);
title ('Demodulated Signal', 'FontSIze', 20);
xlabel ('Time [s]', 'FontSize', 20);
ylabel ('Displacement[m]', 'FontSize', 20);
set(gca,'FontSize',20);
figure (4);
plot(f, y_fft,'r','LineWidth',4)
xlim([0 2])
xlabel('Frequency (Hz)', 'FontSize', 20)
ylabel('Magnitude', 'FontSize', 20)
axis([0,10,0,3000]);
set(gca,'FontSize',20);
%}
figure (5);
subplot(2,1,1);
plot(f,10*log10(P_I));
title ('Power Spectrum Density I');
xlabel('Hz'); ylabel('dB/Hz');
%xlim([0 10]);
plot(f,10*log10(P_Q));
title ('Power Spectrum Density Q');
xlabel('Hz'); ylabel('dB/Hz');
%xlim([0 10]);
plot(f, I_fft,'LineWidth',2)
xlim([0 10])
xlabel('Frequency (Hz)', 'FontSize', 20)
ylabel('Magnitude', 'FontSize', 20)
axis([0,10,0,2500]);
set(gca,'FontSize',20);
plot(f, Q_fft,'LineWidth',2)
xlim([0 10])
xlabel('Frequency (Hz)', 'FontSize', 20)
ylabel('Magnitude', 'FontSize', 20)
axis([0,10,0,2500]);
set(gca,'FontSize',20);
I keep getting errors for the first line. I've also tried working with a data file that I can clearly see in my Workspace and Current Folder. I'm working with someone elses code whenever I run it, the arc tangent demodulation, a second tab pops up in my editor with code called "importdata.m" I have no idea what that is or why it's there.
"Error using importdata (line 139) Unable to open file. Error in arctangentdemodulationcode (line 2) d.data=importdata('a2.txt'); "
2 个评论
KSSV
2020-8-11
Looks like there is user defined function on the name importdata.
Try
which importdata
If it is user defined, rename it to other name.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Chebyshev 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!