Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VHDL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jack Driscoll
VHDL
Commits
d1f48939
Commit
d1f48939
authored
8 months ago
by
Jack Driscoll
Browse files
Options
Downloads
Patches
Plain Diff
matlab file for generating 12 bit noisy samples from msf input
parent
e0d59823
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
MSF/MSF_decoder/tb/matlab/noise_quantised_wave.m
+65
-0
65 additions, 0 deletions
MSF/MSF_decoder/tb/matlab/noise_quantised_wave.m
with
65 additions
and
0 deletions
MSF/MSF_decoder/tb/matlab/noise_quantised_wave.m
0 → 100644
+
65
−
0
View file @
d1f48939
bit_res
=
12
;
sample_length
=
120000
;
fid
=
fopen
(
'msf_sample.csv'
,
'r'
);
binary_sequence
=
fscanf
(
fid
,
'%1d'
)
.'
;
binary_sequence
=
binary_sequence
(:,
1
:
sample_length
);
twelve_bit_array
=
binary_sequence
*
((
2
^
bit_res
-
1
)
-
2
^
(
bit_res
-
3
))
+
(
2
^
(
bit_res
-
4
))
*
ones
(
1
,
sample_length
);
twelve_bit_array
=
movmean
(
twelve_bit_array
,
10
);
num_bits
=
length
(
twelve_bit_array
);
original_time
=
1
:
num_bits
;
high_res_time
=
linspace
(
1
,
num_bits
,
num_bits
*
10
);
% Interpolate to create smooth transitions
%smooth_wave = interp1(original_time, twelve_bit_array, high_res_time, 'pchip');
% Add noise to the signal
noise_amplitude
=
200
;
% Adjust the amplitude of the noise
noisy_wave
=
twelve_bit_array
+
noise_amplitude
*
randn
(
size
(
twelve_bit_array
));
% Scale the noisy signal to ensure it's within the range of 12-bit values
noisy_wave
=
max
(
0
,
min
(
4095
,
noisy_wave
));
% Quantize the noisy signal into 12-bit values
quantized_wave
=
round
(
noisy_wave
);
hex_wave
=
dec2hex
(
quantized_wave
);
writematrix
(
hex_wave
,
"adc_msf_input.csv"
);
% Convert the quantized values to binary strings
binary_wave
=
dec2bin
(
quantized_wave
,
12
);
% Plot the original, noisy, and quantized signals
figure
;
subplot
(
3
,
1
,
1
);
stairs
(
original_time
,
twelve_bit_array
,
'b'
,
'LineWidth'
,
1.5
);
title
(
'Original 12-bit Signal'
);
xlabel
(
'Time'
);
ylabel
(
'12-bit Value'
);
subplot
(
3
,
1
,
2
);
plot
(
original_time
,
noisy_wave
,
'r'
,
'LineWidth'
,
1.5
);
title
(
'Noisy and Smoothed Signal'
);
xlabel
(
'Time'
);
ylabel
(
'12-bit Value'
);
subplot
(
3
,
1
,
3
);
stairs
(
original_time
,
quantized_wave
,
'g'
,
'LineWidth'
,
1.5
);
title
(
'Quantized Signal'
);
xlabel
(
'Time'
);
ylabel
(
'12-bit Value'
);
% Display some results
disp
(
'First 10 original 12-bit values:'
);
disp
(
twelve_bit_array
(
1
:
10
));
disp
(
'First 10 noisy 12-bit values:'
);
disp
(
noisy_wave
(
1
:
10
));
disp
(
'First 10 quantized 12-bit values:'
);
disp
(
quantized_wave
(
1
:
10
));
disp
(
'First 10 quantized 12-bit binary values:'
);
disp
(
binary_wave
(
1
:
10
,
:));
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment