# Forum

#### Welcome Guest

Welcome Guest, posting in this forum requires registration.

 Pages: Author Topic: Simple MATLAB queries - Please Help
JNoq
Newbie
Posts: 11  Simple MATLAB queries - Please Helpon: April 30, 2013, 19:20 Quote

Hi all,

I'm currently converting the MatLAB code to work on R instead.

Could someone please explain the following lines of code for me? Perhaps if you are experienced with R, you may be able to convert?

`start = (trig > thresh);`

Is this, "start var is equal to trig, if it is greater than thresh"

`sif(count,:) = s(ii:ii+N-1);`

Is this, "assign array 'sif' at point 'count' with string 'ii:ii+N-1'"?

`time(count) = ii*1/FS;`

Is this, "assign array 'time' at point 'count' with integer 'ii*1/FS'"?

-----

Y3G
Posts: 23  Re: Simple MATLAB queries - Please Helpon: May 1, 2013, 10:08 Quote

1) start = (trig > thresh);
Is this, "start var is equal to trig, if it is greater than thresh";
Correct.
Since the SW recorded a wav-file with 2 channels, Left for the 20 ms Pulse and right for chirp, he is looking for the index of the Pulse to be up and according to the index that is "up" = above threshold he is populating a new vector.
/// see my comments in the code
count = 0;
thresh = 0;
start = (trig > thresh); % populates a vector with logical 0's and 1's where "trig" >0
for ii = 100:(size(start,1)-N) %looking at the logic vector starting at 100
if start(ii) == 1 && mean(start(ii-11:ii-1)) == 0 % if last sample is 1 and the last 11 consequented samples = 0 then we have a rising edge
%start2(ii) = 1;
count = count + 1; % index counter for final vector
sif(count,:) = s(ii:ii+N-1); % populates our result vector with N Samples (pulsewidth) of the Right channel Wav-samples
time(count) = ii*1/FS; % clculates the time vector accordingly
end

JNoq
Newbie
Posts: 11  Re: Simple MATLAB queries - Please Helpon: May 1, 2013, 13:42 Quote

Thank you very much YSG Just to confirm that the count on my logical vector is:

` 3573760`

So that means that the for loop will loop 100 to 3,573,760! (this is using the range.wave sample in the course syllabus)

Basically the script times out as the loop is so large. Perhaps I have messed up what the Trig or N value should be?

A print out of my Trig value is:

`3473761 entries`

And the print out of my N value is:

` 882`
Y3G
Posts: 23  Re: Simple MATLAB queries - Please Helpon: May 8, 2013, 02:30 Quote

Hi JNoq,
N are the samples per pulsewidth (=Tp). If you have a pulsewidth of 20 ms and your Sample frequency (=FS, which is the Sample Frequency of your PC Soundcard, in here 44.1 kHz) your Vectorsize N should be N=Tp*FS = 0.02 s * 44100 1/s = 882

The "Trig" values are the combined (commulated) Samples that were above Threshold and depends on your record time of wav file. For example if you have a pulse width of 20 ms, which reveals when sampling at 44.1 kHz a vectorlength N of 882 Samples.
Now you recorded Wav file length is 81 sec then,
882 Samples per 20 ms = 44100 Samples per second * 81 sec = 3572100 which is your Trig vector size.

I am adding my comments on all of the code, maybe it helps understanding more,

%Resource: Build a Small Radar System Capable of Sensing Range, Doppler,
%
%Gregory L. Charvat

%Process Range vs. Time Intensity (RTI) plot

%NOTE: set up-ramp sweep from 2-3.2V to stay within ISM band
%change fstart and fstop bellow when in ISM band

clear all;
close all;

%read the raw data .wave file here
%constants
c = 3E8; %(m/s) speed of light

Tp = 20E-3; %(s) pulse time
N = Tp*FS; %# of samples per pulse
%fstart = 2260E6; %(Hz) LFM start frequency for example
%fstop = 2590E6; %(Hz) LFM stop frequency for example
fstart = 2257E6; %(Hz) LFM start frequency for ISM band
fstop = 2544E6; %(Hz) LFM stop frequency for ISM band
BW = fstop-fstart; %(Hz) transmti bandwidth

f = linspace(fstart, fstop, N/2); %instantaneous transmit frequency

rr = c/(2*BW); % range resolution in [m]
max_range = rr*N/2; % max range in [m]

%the input appears to be inverted
trig = -1*Y(:,1); % takes the samples (trigger) from Left channel wav
s = -1*Y(:,2); % takes the samples from the Right channel wav file
%clear Y; % clears the 2 channel origin wav file matrix

%parse the data here by triggering off rising edge of sync pulse
% in other words: Here we take the samples where the sync pulse started "hi"
% remember the Chirp is a triangle, we are not interested in the "downhill"
%
count = 0;
thresh = 0;
start = (trig > thresh); % populates a vector with logical 0's and 1's where "trig" >0
for ii = 100:(size(start,1)-N) %looking at the logic vector starting at 100
if start(ii) == 1 && mean(start(ii-11:ii-1)) == 0 % if last sample is 1 and the last 11 consequented samples = 0 then we have a rising edge
%start2(ii) = 1;
count = count + 1; % index counter for final vector
sif(count,:) = s(ii:ii+N-1); % populates our result vector with N Samples (pulsewidth) of the Right channel Wav-samples
time(count) = ii*1/FS; % clculates the time vector accordingly
end
end
%check to see if triggering works
figure(1);
plot(trig,'.b');
hold on;
% plot(start2,'.r');
% hold off;
%grid on;

%subtract the average
ave = mean(sif,1);
for ii = 1:size(sif,1);
sif(ii,:) = sif(ii,:) - ave;
end

%RTI plot
figure(10);
S = v(:,1:size(v,2)/2);
m = max(max(v));
colorbar;
ylabel('time (s)');
xlabel('range (m)');
title('RTI without clutter rejection');

%2 pulse cancelor RTI plot
figure(20);
sif2 = sif(2:size(sif,1),:)-sif(1:size(sif,1)-1,:);
S=v;
for ii = 1:size(S,1)
%S(ii,:) = S(ii,:).*R.^(3/2); %Optional: magnitude scale to range
end
S = dbv(S(:,1:size(v,2)/2));
m = max(max(S));
imagesc(R,time,S-m,[-80, 0]);
colorbar;
ylabel('time (s)');
xlabel('range (m)');
title('RTI with 2-pulse cancelor clutter rejection');

% %2 pulse mag only cancelor
% figure(30);
%clear v;
%for ii = 1:size(sif,1)-1
% v(ii,:) = v2-v1;
% end
%S=v;
%for ii = 1:size(S,1)
% S(ii,:) = S(ii,:).*R.^(3/2); %Optional: magnitude scale to range
%end
%S = dbv(S(:,1:size(v,2)/2));
%m = max(max(S));
%imagesc(R,time,S-m,[-20, 0]);
%colorbar;
%ylabel('time (s)');
%xlabel('range (m)');
%title('RTI with 2-pulse mag only cancelor clutter rejection');

 Pages: 
Mingle Forum by cartpauj
Version: 1.0.34 ; Page loaded in: 0.053 seconds.