Input not numeric? error
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Alia Hicks
am 14 Aug. 2020
Bearbeitet: Walter Roberson
am 14 Aug. 2020
AdaptFFTCleand.mat is a 4000x2 matrix of positve and negative real numbers. This is the error I get when running said code:
Error using filter
Invalid data type. Input arrays must be numeric or logical.
Error in LifeSings (line 18)
z1=filter(B,1,data(:,2)); % I channel signal
"
Error is in line 14 :"z1=filter(B,1,data(:,2)); % I channel signal
clc
clear all
load AdptFFTCleand.mat
ich = AdptFFTCleand.VarName1;
qch = AdptFFTCleand.VarName1;
data = AdptFFTCleand ; % import data options
fs=100; % Sampling frequency
fc=40; % carrier frequency (corner frequency)
fc_n = fc .* 2 /fs; % normalized frequency
B = fir1(1000,fc_n); % filter basics
z1=filter(B,1,data(:,2)); % I channel signal
z2=filter(B,1,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,2,1) % new subplot option
plot (Time, I);
legend ('I');
xlim([10 60])
title ('I channel');
xlabel ('Time [s]');
ylabel ('Amplitude [V]');
subplot(2,2,2)
plot (Time, Q, 'r');
xlim([10 60])
legend ('Q');
title ('Q channel');
xlabel ('Time [s]');
ylabel ('Amplitude [V]');
subplot(2,2,3)
plot(f, I_fft)
xlim([0 2])
xlabel('Frequency (Hz)')
ylabel('Magnitude')
axis([0,10,0,2500]);
title ('I channel FFT');
% set(gca,'FontSize',20);
subplot(2,2,4)
plot(f, Q_fft)
xlim([0 2])
xlabel('Frequency (Hz)')
ylabel('Magnitude')
axis([0,10,0,2500]);
title ('Q channel FFT');
1 Kommentar
Matt J
am 14 Aug. 2020
Did you intend to attach AdaptFFTCleand.mat? We cannot run the code otherwise.
Akzeptierte Antwort
Matt J
am 14 Aug. 2020
Bearbeitet: Walter Roberson
am 14 Aug. 2020
AdaptFFTCleand is a 4000x2 matrix of positve and negative real numbers.
It isn't possible that AdptFFTCleand is a numeric matrix if you are able to index it like a struct in these lines,
ich = AdptFFTCleand.VarName1;
qch = AdptFFTCleand.VarName1;
Hence also, data as set up this way,
data = AdptFFTCleand ;
would also be a struct and not a numeric variable. That would explain why filter() complains.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Fourier Analysis and Filtering finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!