Simple MATLAB Scrambler: Step-by-Step Guide and Code Example

  • Thread starter Gpaiva
  • Start date
  • Tags
    Matlab
In summary, the conversation was about building a simple scrambler using MATLAB. The individual was having trouble with their code and explained their approach, specifically mentioning that their code was not working. They also shared a portion of their code and asked for suggestions. The expert provided a summary of the conversation and suggested that the issue may be related to the sampling frequency being used incorrectly when calculating the frequencies for filtering. They also offered a possible solution and wished the individual luck with their project.
  • #1
Gpaiva
1
0
Hello,

I'm trying to build a simple scrambler using matlab, as show on the picture below:

[PLAIN]http://img94.imageshack.us/img94/1381/blocks.jpg

Its not in english, but I think anyone can understand it. The first filter is a high pass filter and the second is a low pass.
The idea is simple: if the input is m(t) the output is y(t), and if you input y(t) you recover m(t) as the output.

What I have tried to do is this (ill past the MATLAB code below): Import an wave file into matlab, multiply it by cos(2pifct), do a Fourier transform, filter it by "zeroing" the high frequency elements, do an Inverse Fourrier transform, multiply it by cos[2pi(fc+W)t], do a Fourrier transform, aply the second filter and finally do an Inverse Fourrier transform.

Here are the first lines on my code. Its already broken at this point because S1 is nothing but zeroes.

%--- Reads the wave and adds the channels, so I end up mono
[M1 FS NBITS] = wavread('3333.wav');
m= M1(:,1) + M1(:,2);
kk=size(m) ; k=kk(1);

t=(0:(k-1))/FS; % A vector with the instants of time when there
% was sampling

fc = 500000; %-- I chose fc 500 KHz.
A = 1; %-- I chose A 1.


%-- Multiply m(t) by cos(2pifct), as show on the block diagram.
s1 = m'.*(1*cos(2*pi*fc*t));

%-- S1 is the Fourrier transform of s1.
S1= fft(s1);

%--- Calculates the size of s1
tt = size(s1); t=tt(2);


w=[(-t/2)+1 : t/2]; %-- Auxiliar vetor, to help calculate Freqs

Freqs = w' * (FS/t); % Each element of Freqs contains a frequency
% corresponding to an elemento of S1, that is,
% the signal has amplitude S1(i) with
% frequency Freqs(i) for any i.


% Finds frequencies lower than fc and greater than -fc
Freqs1 = find( Freqs >= -fc & Freqs <=fc );

%Filters the high frequencies
S1(Freqs1)=0;

s2 = ifft(S1); % Inverse Fourier transform of S1

%--- Segundo multiplicador, A.cos[2pi(fc+W)t]
s3 = s2'.*(1*cos(2*pi*(fc + t/2)*t));


Ill stop here because it doesn't matter anyway, the problem is earlier on.
Thanks for the help, any suggestions are appreciated, even if it means ill have to throw this code away and start from scratch.
 
Last edited by a moderator:
Physics news on Phys.org
  • #2


Hello,

Thank you for sharing your code and explaining your approach. I can see that you have a good understanding of the concept behind the scrambler and have put a lot of thought into your implementation.

However, I think the issue you are facing is that you are not taking into account the sampling frequency when calculating the frequencies for your filter. In your code, you are using the sampling frequency (FS) to calculate the time vector (t), but then you are using the length of s1 (which is related to the number of samples) to calculate the frequencies in Freqs. This could result in incorrect frequencies being selected for filtering.

I would suggest using the sampling frequency (FS) to calculate the frequencies in Freqs, so that they are consistent with the time vector (t). This can be done by dividing the frequencies in Freqs by the number of samples (k) and multiplying by the sampling frequency (FS). This will ensure that the frequencies are in the correct range and correspond to the correct elements in S1.

I hope this helps and good luck with your project!
 

1. What is a Simple Scrambler on MatLab?

A Simple Scrambler on MatLab is a program that takes a message signal and scrambles it using a pseudorandom sequence. This process is commonly used in telecommunications to ensure privacy and secure transmission of data.

2. How does a Simple Scrambler work on MatLab?

A Simple Scrambler on MatLab works by taking a message signal and XOR-ing it with a pseudorandom sequence, also known as a scrambling code. This code is generated using a linear feedback shift register (LFSR) and is synchronized with the receiver to properly descramble the message.

3. What is the purpose of using a Simple Scrambler on MatLab?

The purpose of using a Simple Scrambler on MatLab is to add a layer of security to transmitted data. By scrambling the message signal, it becomes difficult for unauthorized parties to intercept and understand the data being transmitted.

4. Can a Simple Scrambler on MatLab be used for any type of data?

Yes, a Simple Scrambler on MatLab can be used for any type of data as long as it is in the form of a digital signal. This includes audio, video, and text data.

5. Is a Simple Scrambler on MatLab reversible?

Yes, a Simple Scrambler on MatLab is reversible as long as the receiver has access to the same scrambling code used by the transmitter. The receiver can use the same process of XOR-ing the scrambled signal with the code to retrieve the original message signal.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
952
  • Engineering and Comp Sci Homework Help
Replies
3
Views
987
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
Replies
2
Views
604
  • Engineering and Comp Sci Homework Help
Replies
11
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
Back
Top